220 34490 <7bf0d2563477e89a8faa3ca2daa18f67@kdab.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Marc Mutz <marc.mutz@kdab.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Auto return type deduction surprises
Date: Tue, 26 Sep 2017 09:53:28 +0200
Organization: KDAB
Lines: 47
Approved: news@gmane.org
Message-ID: <7bf0d2563477e89a8faa3ca2daa18f67@kdab.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"; format=flowed
X-Trace: blaine.gmane.org 1506412556 16517 195.159.176.226 (26 Sep 2017 07:55:56 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 26 Sep 2017 07:55:56 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRPXDOU7ECRBBUQVDHAKGQEMVVGXCI@isocpp.org Tue Sep 26 09:55:48 2017
Return-path: <std-proposals+bncBCRPXDOU7ECRBBUQVDHAKGQEMVVGXCI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f200.google.com ([209.85.128.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCRPXDOU7ECRBBUQVDHAKGQEMVVGXCI@isocpp.org>)
	id 1dwkiV-0003Y7-QA
	for gclcip-std-proposals@m.gmane.org; Tue, 26 Sep 2017 09:55:43 +0200
Original-Received: by mail-wr0-f200.google.com with SMTP id g29sf1644051wrg.8
        for <gclcip-std-proposals@m.gmane.org>; Tue, 26 Sep 2017 00:55:51 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1506412551; cv=pass;
        d=google.com; s=arc-20160816;
        b=C4iNONlaE5dQeZ/ALOSjO1uGvCyL4JX34VTOCMXNvvPyn49yYoDHli9eQpofQZtXMb
         mOcd6sPt8FMpI7Lhh8D0p+RO+EGy+3OO5bRRpOPkKHXoBj12y5mrcnTMkFVSsW4tSl8o
         KzdJw9FHq+6JK43Qc+4BAsDuXl2n5tkeXmkiNWzc9HBZMV+npm+Dy0f/0AOOt8CuPC5A
         YBcgSpRlWV+olv4epPPCgRsM0quCh8y6705OqIfAZAtd7w/CQypUfyfBb2CeS6FQQfqq
         G3RbtLU2naH8zfYImE0y5BVYc7YcgizXX+3l/YfmZ1381+kK1GssNJrEiSZJANTGGfTJ
         A01Q==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:message-id:organization
         :subject:to:from:date:mime-version:sender:arc-authentication-results
         :arc-message-signature:arc-authentication-results;
        bh=cPQrB3h8yoLEyDVBc+Q3tX+7d1rt1KMg/wtDpRcQkr4=;
        b=VyaV7iGng/80T+qvLTvcsO97FpkOemnv+6Vi02goTHDarXRI5BSLotPvmKbchIqR7m
         g90vjy1Dx8G3E5XrAMnMshkLGVIrWlNFBy8DOs2h/03U0JxLmt5zBxGiNumD23tTibmu
         sVwAN+zhnSy6KPH+0v89vWzKcXGHWw4LaRflbbcRMXWFSJ7+fGZMYYZsgYLge6aR54y+
         xWjsas4TrLBF3nnKNP3Z5Q68+BV2ebfgYTmANbiZ9I4OtcGYf18+NFRBwdUWhw2NZFAL
         HJdtbOWCyQzyjjmAZ0jNBgHE/hhofr1sDhyx966Lu+jy7xUZd0d2+5yfiTdnNgN0P37N
         +A4g==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) smtp.mailfrom=marc.mutz@kdab.com
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:sender:mime-version:date:from:to:subject
         :organization:message-id:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=cPQrB3h8yoLEyDVBc+Q3tX+7d1rt1KMg/wtDpRcQkr4=;
        b=sy3b7CWWVFpfaq0s2NXw1bU9naGKHqUkzDIXfJ4QGUNISRBONGoOS9m5NHdeGRYyrV
         w8YUNr87Y2gKVL7WbhujB0UdF0DElJM5kHc91Cs+BoVXvz+KogNhNXVbw4+KAifsYuy1
         63N+p5l/mbtQJUDcVvD3v64IENX0nf0bSquuTaj1+/lKpHF9LI2VftaaMKwI4hHdPg00
         HH7dWM0WSR7x1LbrSaWKsEdzHMYfI39ut0z7libfL5TZ0S/cUYZkFnlXspRutVGNgV6D
         VP7h4ynqKQjA1/E4iciyPv5RQ458vXD/5IKy8gsP2JPAgb5nlth1MXW6ufkTD1LjhCl2
         8nvA==
X-Gm-Message-State: AHPjjUgvpN1c3ths3fH0wlFFID/UkkfNj6PtlXerKcmpagNjuIgP9lzN
	u88p0GXt6XpFhXmbyjdJBYTeNw==
X-Google-Smtp-Source: AOwi7QBGmF4VbwexVmQhr6GJJB5D1IBFAz5b7dVjiQqoI4KbhJZq2tDweldgNS6vvBuw9PqA8ztOMQ==
X-Received: by 10.28.16.8 with SMTP id 8mr248264wmq.31.1506412551260;
        Tue, 26 Sep 2017 00:55:51 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.223.163.207 with SMTP id m15ls3205696wrb.13.gmail; Tue, 26 Sep
 2017 00:55:49 -0700 (PDT)
X-Received: by 10.223.156.129 with SMTP id d1mr9093585wre.166.1506412549884;
        Tue, 26 Sep 2017 00:55:49 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1506412549; cv=none;
        d=google.com; s=arc-20160816;
        b=iaNTFXjYDLgzoTUT6GKL0Wl0Di25BunaK9PTo/bza7GTs1wVT9kZi1ZvQ3TiAVNqRJ
         AyzQ3pr2HZNxAkTn8p8qjBgTPbG2q8HyPKOmVMlLd4yWWrvIfTkk7+XrzmBs6Y6odVnb
         CmmB1X0ieDHsbU0YP3k0OpW5RlnJSycnmrueTvFHUTfn1OWT5at3x//85JhPQxVZoIV6
         uOEIj6aZVOLJrjxjxOs61cwObW8lLdjiIfvUdzl4Pqk79rhEf4Qz9ZeK5t7Y5Eq6hyN8
         fh5oBbywp3NfgTiAIVRr9xeVQsvCDobqxqw4kJPSx3pPRepYlv5RH81+TT7EModufpOm
         TiuQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=message-id:organization:subject:to:from:date
         :content-transfer-encoding:mime-version:sender
         :arc-authentication-results;
        bh=G59nmxhgp2U3B5CCosy8cMQY0QrXGIEGbxQi/bsj41U=;
        b=HmVweFWlS9Gekd0Mgnnd9SOeLGxc+96upezsXCniGOBGY8vcEYHFgN+JIW8d4qcPYx
         CoYt56IuksqgjXAADvY9XcpXuwkfxZpSJTEXjjPDTNKQwJguVjkC/GbXQMmme/Bv8Gt+
         +yaSmEyuR9BJY90B0xPxmO2j9AKqVJPpqVfBRXvWR7f2S3oyBo35jbc6KxBqaNLq/00J
         ET5sk1DPodjKgWSWjV7ez+C4zi3/A76VFxFtYRZzNRm9RRamyaJtPppxyKoO0sOevLbW
         iriYIVogRpLQrv9cAyT2HtcTrLMFlPEncezWU/F/QAxpjcD1auI5Jrn1+hXLVrRKl/5Z
         qIIw==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) smtp.mailfrom=marc.mutz@kdab.com
Original-Received: from mail.kdab.com (mail.kdab.com. [176.9.126.58])
        by mx.google.com with ESMTPS id n4si6991658wrf.267.2017.09.26.00.55.49
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 26 Sep 2017 00:55:49 -0700 (PDT)
Received-SPF: pass (google.com: domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) client-ip=176.9.126.58;
X-Virus-Scanned: amavisd-new at kdab.com
Original-Sender: marc@kdab.com
X-Sender: marc.mutz@kdab.com
X-Original-Sender: marc.mutz@kdab.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of marc.mutz@kdab.com designates 176.9.126.58 as permitted sender) smtp.mailfrom=marc.mutz@kdab.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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:34490
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/34490>

Hi,

Why do these semantically identical pieces of code have different syntax 
rules?

   template <typename Map, typename Lookup>
   auto find(Map &map, const Lookup &key)
   {
       const auto it = map.find(key);
       if (it == map.end())
           return std::nullopt;
       else
           return std::optional{*it}; // error: inconsistent deduction 
for auto return type
   }

   template <typename Map, typename Lookup>
   auto find(Map &map, const Lookup &key)
   {
       const auto it = map.find(key);
       return it == map.end() ? std::nullopt : std::optional{*it}; // OK, 
-> std::optional<Map::value_type>
   }

iow: Why do auto return types have to have identical types, and don't 
just use the rules for the ternary operator?

And why, in the first case, can I not say

    auto find(Map &map, const Lookup &key) -> std::optional
    {

iow: why doesn't ctor template argument deduction work for trailing 
return types?

Is/was this a conscious decision against, or would a proposal 
adding/changing these be welcome?

Thanks,
Marc

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7bf0d2563477e89a8faa3ca2daa18f67%40kdab.com.

.
