220 30195 <7d89ec43-c691-44d8-bcb5-74dcda9eb493@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: enum_cast proposal
Date: Tue, 3 Jan 2017 11:59:46 -0800 (PST)
Lines: 168
Approved: news@gmane.org
Message-ID: <7d89ec43-c691-44d8-bcb5-74dcda9eb493@isocpp.org>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org> <2998762.etaySSRi7N@tjmaciei-mobl1> <85e681ea-20cb-5d87-d337-6b472e35eb11@wanadoo.fr>
 <2225413.PkzHcSPZVx@tjmaciei-mobl1>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2653_46906257.1483473586093"
X-Trace: blaine.gmane.org 1483473590 3674 195.159.176.226 (3 Jan 2017 19:59:50 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 3 Jan 2017 19:59:50 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBMUFWDBQKGQEC6RNXYQ@isocpp.org Tue Jan 03 20:59:45 2017
Return-path: <std-proposals+bncBCEKFTV6ZUMBBMUFWDBQKGQEC6RNXYQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f70.google.com ([74.125.83.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBMUFWDBQKGQEC6RNXYQ@isocpp.org>)
	id 1cOVFH-0008SA-Fr
	for gclcip-std-proposals@m.gmane.org; Tue, 03 Jan 2017 20:59:43 +0100
Original-Received: by mail-pg0-f70.google.com with SMTP id g1sf1309167468pgn.3
        for <gclcip-std-proposals@m.gmane.org>; Tue, 03 Jan 2017 11:59:47 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=drTHkwxzxB+x1/mNOFORba68gMbMth7YgtywJubwdz0=;
        b=seqfgw7WRNg5e9vs9kjkZNhRgXlo4NWSWD8lmyz88MzmZgonYWJB2peCqA1B7cJbvK
         2JGEOMF1Y9F3IWEKsKnLC2qUl+VTOWvEYZOjSecj2U1rSm8Tp2jOwqryhI8VEsjmJeVS
         jopdwWXREUVHsjKiRykcaBgPcVhW1UQ+mtkvvvKLJ4WEFhBb3Agi8v6Hyb9h/P33xxUb
         KoPbzZADmX44fYfWgT+EYp+aJVUWYi43T3F+RmiGuynac2MAWVvenkV+ZO16NGNgVT06
         cA/TzR4dH7XHRdM5sEm18dp5/9GHuTa7wWgVJd/0XH3/LtVzyPbMK5Us44M/MqsaMHnA
         +0WA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=drTHkwxzxB+x1/mNOFORba68gMbMth7YgtywJubwdz0=;
        b=Xw9SIqBZwU174d2C4Z3QV7o4D9yTbKhaehun5xuFZjG4j37WohZ0e1niGYBbPTBr8U
         FvSZiivrQ/n1fbe4Dkhs+KZImVfoVGxnIA/HTSAA8Nss7vtsN0WduTl2kaOVabdfcOBp
         RR+kbDzzTC0Rz2WPd/M5T4ZIMbLcI9k/l+VfETMVRaDqg3LQE2GlVWkJuBI8L6yZzuIp
         KrdjmByf5q+/82x8KQMiycBe2Rj+xxG44g/VB4cd3H39tVXQNRKIg+Boz+CE1TOqH1O7
         LFAwCxRy3pu14rZdUPR52zdfSN7AvGxfk4zTwBWpbgrnFuXYPt8xmLcaLebCzpPAdE0R
         clbg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=drTHkwxzxB+x1/mNOFORba68gMbMth7YgtywJubwdz0=;
        b=EZ0lLEpQheSN6ngyZw/xktB62Gg5XVV0FXO/nAV0PH4f4VIT7YPGPFXU0tupFLXsXd
         BdTYKK35lofuGViE1peno8etGwuu0Im5+gMWzRx4tQOyk98UwNXuhR67QH4gL+X+zic9
         8mBa4Iyoprdtw8+GMk0pvTK+yoUMZW7DhgEfM0Gm9K2Oj+nWupbYhMvZtdtp/KZt1Eb2
         kMqvt6+lm/SXkEjD70BRmvUugAlRl1XeiHvPtH7VH2e6QgCbmTlbiPFpOB7xtZEFUlZ6
         NluwgrWH8M/4U7DN162vC1OgDYaXuRwIb9wYxwwAzMAEs9f+NE+kZZWeuQO2lygHEuq0
         8Tiw==
X-Gm-Message-State: AIkVDXKBzt0YVTEBwupPKmf0/RwoAaPpv1HwvoRzlb16nt+V4nMVQeRXYmRRbIIKDJFbRA==
X-Received: by 10.99.171.67 with SMTP id k3mr34414480pgp.46.1483473587296;
        Tue, 03 Jan 2017 11:59:47 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.11.115 with SMTP id p48ls18816613otd.19.gmail; Tue, 03 Jan
 2017 11:59:46 -0800 (PST)
X-Received: by 10.157.35.89 with SMTP id k25mr2147444otd.11.1483473586558;
        Tue, 03 Jan 2017 11:59:46 -0800 (PST)
In-Reply-To: <2225413.PkzHcSPZVx@tjmaciei-mobl1>
X-Original-Sender: jmckesson@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: <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:30195
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30195>

------=_Part_2653_46906257.1483473586093
Content-Type: multipart/alternative; 
	boundary="----=_Part_2654_514702518.1483473586094"

------=_Part_2654_514702518.1483473586094
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Tuesday, January 3, 2017 at 2:09:19 PM UTC-5, Thiago Macieira wrote:
>
> On ter=C3=A7a-feira, 3 de janeiro de 2017 18:53:02 BRST Vicente J. Botet=
=20
> Escriba=20
> wrote:=20
> > Le 03/01/2017 =C3=A0 16:56, Thiago Macieira a =C3=A9crit :=20
> > > On ter=C3=A7a-feira, 3 de janeiro de 2017 07:06:10 BRST m.ce...@gmail=
..com=20
> <javascript:>=20
> > > wrote:=20
> > >=20
> > > Also, where did that optional come from? If it's going to use=20
> optional,=20
> > > then it needs to be a library feature.=20
> >=20
> > I'm not for the optional return type, but we have already a lot of case=
s=20
> > where syntactic sugar as range-based for loop and structure binding=20
> > depends on library.=20
> > So I'm not sure this could be an argument against optional.=20
>
> Those are quite different things. In fact, they show how to *not* depend=
=20
> on=20
> the library in the first place. Ranged fors and structured bindings only=
=20
> require that functions called begin, end, and get exist. So I can add any=
=20
> function of my own with those names and it will work. And structured=20
> bindings=20
> are very specifically *not* a std::tuple. They're something different.=20
>
> So enum_cast could return an optional-like opaque type defined by the=20
> compiler=20
> (like structured bindings and lambdas) which can be converted to=20
> std::optional=20
> on construction.
>

First, a correction. Structured binding does not deal in an "opaque type=20
defined by the compiler". It deals in exactly whatever type the=20
initializing expression resolves to. So long as the type has the specified=
=20
characteristics or provides the interface required, it will work. But the=
=20
compiler is not inventing some type behind-the-scenes.

Further, I think your analogy is rather wrongheaded. Ranges and product=20
types are categories of types provided by the user. The language is=20
defining mechanisms for the user to provide a type which can be consumed by=
=20
the language. `enum_cast` is not like that at all. It *returns* a type,=20
based on basic values provided by the user. For the optional-version of it,=
=20
that type would have all of the properties of `optional`.

Lastly, having `enum_cast` work via some compiler-defined type is rather=20
extreme for something as simplistic as this, don't you think? There are=20
only so many ways to implement an "optional", and you can define implicit=
=20
conversions from `std::optional` type to yours with little penalty. The=20
conversion can even be `constexpr`, just like `std::optional`, so you would=
=20
suffer no loss of performance in constexpr contexts.

--=20
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 e=
mail 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/7d89ec43-c691-44d8-bcb5-74dcda9eb493%40isocpp.or=
g.

------=_Part_2654_514702518.1483473586094
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, January 3, 2017 at 2:09:19 PM UTC-5, T=
hiago Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On ter=C3=
=A7a-feira, 3 de janeiro de 2017 18:53:02 BRST Vicente J. Botet Escriba=20
<br>wrote:
<br>&gt; Le 03/01/2017 =C3=A0 16:56, Thiago Macieira a =C3=A9crit :
<br>&gt; &gt; On ter=C3=A7a-feira, 3 de janeiro de 2017 07:06:10 BRST <a hr=
ef=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"qB3FkV6BCwAJ"=
 rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return t=
rue;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">m.ce...@gm=
ail.com</a>
<br>&gt; &gt; wrote:
<br>&gt; &gt;=20
<br>&gt; &gt; Also, where did that optional come from? If it&#39;s going to=
 use optional,
<br>&gt; &gt; then it needs to be a library feature.
<br>&gt;=20
<br>&gt; I&#39;m not for the optional return type, but we have already a lo=
t of cases
<br>&gt; where syntactic sugar as range-based for loop and structure bindin=
g
<br>&gt; depends on library.
<br>&gt; So I&#39;m not sure this could be an argument against optional.
<br>
<br>Those are quite different things. In fact, they show how to *not* depen=
d on=20
<br>the library in the first place. Ranged fors and structured bindings onl=
y=20
<br>require that functions called begin, end, and get exist. So I can add a=
ny=20
<br>function of my own with those names and it will work. And structured bi=
ndings=20
<br>are very specifically *not* a std::tuple. They&#39;re something differe=
nt.
<br>
<br>So enum_cast could return an optional-like opaque type defined by the c=
ompiler=20
<br>(like structured bindings and lambdas) which can be converted to std::o=
ptional=20
<br>on construction.<br></blockquote><div><br>First, a correction. Structur=
ed binding does not deal in an &quot;opaque type defined by the compiler&qu=
ot;. It deals in exactly whatever type the initializing expression resolves=
 to. So long as the type has the specified characteristics or provides the =
interface required, it will work. But the compiler is not inventing some ty=
pe behind-the-scenes.<br><br>Further, I think your analogy is rather wrongh=
eaded. Ranges and product types are categories of types provided by the use=
r. The language is defining mechanisms for the user to provide a type which=
 can be consumed by the language. `enum_cast` is not like that at all. It <=
i>returns</i> a type, based on basic values provided by the user. For the o=
ptional-version of it, that type would have all of the properties of `optio=
nal`.<br><br>Lastly, having `enum_cast` work via some compiler-defined type=
 is rather extreme for something as simplistic as this, don&#39;t you think=
? There are only so many ways to implement an &quot;optional&quot;, and you=
 can define implicit conversions from `std::optional` type to yours with li=
ttle penalty. The conversion can even be `constexpr`, just like `std::optio=
nal`, so you would suffer no loss of performance in constexpr contexts.<br>=
</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7d89ec43-c691-44d8-bcb5-74dcda9eb493%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7d89ec43-c691-44d8-bcb5-74dcda9eb493=
%40isocpp.org</a>.<br />

------=_Part_2654_514702518.1483473586094--

------=_Part_2653_46906257.1483473586093--

.
