220 11276 <CAGdQazdTYTYvwt6gDqU5U2WBeHaU4G8-za85D6OQ+Lp+xpeq2w@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Sebastian Gesemann <s.gesemann@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: return type sugar (orthogonal to auto foo() {} )
Date: Thu, 12 Jun 2014 16:10:47 +0200
Lines: 44
Approved: news@gmane.org
Message-ID: <CAGdQazdTYTYvwt6gDqU5U2WBeHaU4G8-za85D6OQ+Lp+xpeq2w@mail.gmail.com>
References: <30a83c0d-00e6-462a-822e-a1789787ec05@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1402582257 3102 80.91.229.3 (12 Jun 2014 14:10:57 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 12 Jun 2014 14:10:57 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDO4ZQHJWIBRB2HJ42OAKGQENMKOUIA@isocpp.org Thu Jun 12 16:10:50 2014
Return-path: <std-proposals+bncBDO4ZQHJWIBRB2HJ42OAKGQENMKOUIA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f197.google.com ([209.85.214.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDO4ZQHJWIBRB2HJ42OAKGQENMKOUIA@isocpp.org>)
	id 1Wv5iL-0004bJ-BB
	for gclcip-std-proposals@m.gmane.org; Thu, 12 Jun 2014 16:10:49 +0200
Original-Received: by mail-ob0-f197.google.com with SMTP id uz6sf6199298obc.4
        for <gclcip-std-proposals@m.gmane.org>; Thu, 12 Jun 2014 07:10:48 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=4Pojx8/zvyVDA9T0w5VasQYunWgJ6jBpo5JtCb7QoJQ=;
        b=gBLvfQpZdEkvWUXDDtLmD/NyB33P1rihPHgSRFiAFKojzUpkug/RIgVjMT8hUvkpN9
         CaIemcfDWDIX6bkw0tyGyrat0JYyMtgSkn7Pru2/Rs78+kP1epbWuROdMA1D11rogle2
         pDZvZJZvbcjFZlSVPZ7sQv4tNHVZsPK4YB1KAfgYtwF+3dmJqD9xSqQSfcGtnJWJr/1C
         xvJWRZRr4TlIAPQwM55QrMN0gHVqUCUMaQsfWj+vccpNNYvXCzWbGJxJq4jHyNRpysay
         p3dmNNsqFOuObuiqiZ/i+cdX3zlk1/BqTYCFhA4gSU1jJxnUPyiYWEV89wMSqgjxner2
         IyKA==
X-Gm-Message-State: ALoCoQlcFhHZ0St/tUyuJBozA75RFA+qaUQToH2T1QsP8/erZAfLsJVob0sBfogjvjKDXPgQaX2f
X-Received: by 10.182.29.1 with SMTP id f1mr7263451obh.23.1402582248449;
        Thu, 12 Jun 2014 07:10:48 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.48.112 with SMTP id n103ls3064024qga.86.gmail; Thu, 12 Jun
 2014 07:10:47 -0700 (PDT)
X-Received: by 10.58.246.132 with SMTP id xw4mr45853320vec.2.1402582247821;
        Thu, 12 Jun 2014 07:10:47 -0700 (PDT)
Original-Received: from mail-qa0-x22a.google.com (mail-qa0-x22a.google.com [2607:f8b0:400d:c00::22a])
        by mx.google.com with ESMTPS id b4si1221024qaw.71.2014.06.12.07.10.47
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 12 Jun 2014 07:10:47 -0700 (PDT)
Received-SPF: pass (google.com: domain of s.gesemann@gmail.com designates 2607:f8b0:400d:c00::22a as permitted sender) client-ip=2607:f8b0:400d:c00::22a;
Original-Received: by mail-qa0-f42.google.com with SMTP id dc16so1739982qab.29
        for <std-proposals@isocpp.org>; Thu, 12 Jun 2014 07:10:47 -0700 (PDT)
X-Received: by 10.224.63.145 with SMTP id b17mr6309957qai.38.1402582247695;
 Thu, 12 Jun 2014 07:10:47 -0700 (PDT)
Original-Received: by 10.96.109.194 with HTTP; Thu, 12 Jun 2014 07:10:47 -0700 (PDT)
In-Reply-To: <30a83c0d-00e6-462a-822e-a1789787ec05@isocpp.org>
X-Original-Sender: s.gesemann@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of s.gesemann@gmail.com designates 2607:f8b0:400d:c00::22a as
 permitted sender) smtp.mail=s.gesemann@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:11276
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11276>

On Thu, Jun 12, 2014 at 12:16 PM, walter1234 wrote:
> Coming back to C++ from Rust, one thing begin to miss is the 2way type
> inference: its a nice choice on their part, you write the types in the
> signature, then the types in the body are inferred.
>
> But perhaps a significant amount of this use could be covered by having
> sugar to access the declared return type of a function within its own body.
>
> imagine
>
> auto foo(  args...  )->decltype(....some expression based on args...) {
>
>       return_type  accumulator;     // 'return_type' is a shortcut for
> whatever this functions declared return type is..
>       ... do stuff with accumulator...
>
>      return accumulator.
> }
>
> ways of doing that without a new keyword, perhaps 'decltype(return)' , any
> other ideas..
> In some ways this would go beyond what rust currently does. (rust can't yet
> use an expression for the return type, although making it generic often
> works because of how the return types are inferred by callers)

I'm not sure about the utility for such a short cut -- given the fact
that in C++14 you can do something like this:

  // note: no trailing return type
  auto foo(int x, double y) {
    return x+y;
  }

Compared to what you suggest, this is the other way around: The return
type can be deduced from whatever the function returns.

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
