220 30470 <24e58aad-ecbc-4c83-a21b-de56ea4c1db0@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: Re: enum_cast proposal
Date: Tue, 10 Jan 2017 11:30:40 -0800 (PST)
Lines: 253
Approved: news@gmane.org
Message-ID: <24e58aad-ecbc-4c83-a21b-de56ea4c1db0@isocpp.org>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org>
 <57258435-5d82-48e7-8ed7-3c38682418fb@isocpp.org>
 <a35d9f20-9e4f-4789-b7e5-5cb08f99e6bd@isocpp.org>
 <e779f1ca-8f05-7eda-72c8-89a9a5215c62@wanadoo.fr>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_718_171003813.1484076640633"
X-Trace: blaine.gmane.org 1484076658 8341 195.159.176.226 (10 Jan 2017 19:30:58 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 10 Jan 2017 19:30:58 +0000 (UTC)
Cc: m.cencora@gmail.com, gmisocpp@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBYPM2TBQKGQETLMPVNQ@isocpp.org Tue Jan 10 20:30:52 2017
Return-path: <std-proposals+bncBCEKFTV6ZUMBBYPM2TBQKGQETLMPVNQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f198.google.com ([209.85.161.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBYPM2TBQKGQETLMPVNQ@isocpp.org>)
	id 1cR27x-0000Kr-VP
	for gclcip-std-proposals@m.gmane.org; Tue, 10 Jan 2017 20:30:38 +0100
Original-Received: by mail-yw0-f198.google.com with SMTP id v73sf54883781ywg.2
        for <gclcip-std-proposals@m.gmane.org>; Tue, 10 Jan 2017 11:30:42 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc: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=Mge03ACt51jir2JpRb9tZ0kSwUScWfaMOurGjcvnsII=;
        b=L1nuZPdbI/6t6U8GsHwnFmtevQj3rrfOFxlXWMJLjcYHmLMNgsCQLH8bMlEICWyUFa
         JmG9eOI9kojOWRC7+NHcv/0BcsZGOmfjq48dVc5xiQCNrO7p/eM3ShwS9uZtm4pWaI2U
         Hoh1wT+eWRrNnv0CTppjp4CQw08Txw1mmVr8RiKa/Pn6RW+PpauqD/Bicr4+ZcllQbvr
         v7HuLMY9WmEL/x3rjKWnL28eXes848IgUKO7v0B9gja6j5N0r8QQGrz7GUEzANgPsa+O
         xBeSjg/OzT3MQUsGO/UQb6IZ+VIwcUiZxrktCBYPud0kHnxGLYEbINKIHzrm7an5hn8J
         Girw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc: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=Mge03ACt51jir2JpRb9tZ0kSwUScWfaMOurGjcvnsII=;
        b=ULHMskVxW59py5lyXbHaHQOV0oL1duvNKsxPRNb7KeUR78CwbgUHld/FMSaAUNXnWY
         njZ+4k26CdGLsjzvfRB7H5dBbfK7auF2MG5Hqrn1ynzT863WiTxsQDXty0b0yepwjA7A
         ytjF/FZ5vPcrLatNL5XjkJlR4rEsS3rltsjZzuIHrlhFrn6m84q6cVo2Uavd15z1gLlg
         /PE3NA9yHkgFWVa1taykHza3pbtuRWMsT/xyP4kfXdR0a1YUviG88e7gDI/ZWgEnKtlP
         qWUBMneNCI+Jk3Fpw55w6c1c4DCLhzSAI/eTLEar5h+WGhOMIEeO3wFsatSlZfzaImSh
         atXg==
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:cc: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=Mge03ACt51jir2JpRb9tZ0kSwUScWfaMOurGjcvnsII=;
        b=IO1KEGwPEVN2yhBEwTsdW1qFhEFzHlomYUM3Vreht1dWzOKj7lOckzHcgWaTKLLRcP
         JZUcqbhhkOal2uxHPTy75moCqFMVEB/+yBnrX1DFBOk3ribgDA3PwI8Fa5bIHRuEwinO
         x599iwe4U/m/ck3DMZyAT3KgRmmxoA9YYYDCHZQxmJ7Es+s7DF50XOvReYEzCZ0YC7Yo
         q7iYFEpPqin9NV3mmS6z+Bwgr+VtMWhpBur3hvJ8b68jaJqVIIGzDDq1fIPw/94UgXxQ
         yGpbIlZ6ob+Vmm+n7W7reJgon0U0NR6Wfn5WQyU3pKYB/UJ4Qxx4AvoX4otM0ecDRhyv
         OeQw==
X-Gm-Message-State: AIkVDXKVmUNMecqSp7F93g6WnRuXXxoPtZYBWxwdQc3LPPY7y9WsSalyq8Z0eQmcjojneg==
X-Received: by 10.13.201.133 with SMTP id l127mr1497418ywd.70.1484076642016;
        Tue, 10 Jan 2017 11:30:42 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.36.109 with SMTP id p100ls2570770ota.10.gmail; Tue, 10 Jan
 2017 11:30:41 -0800 (PST)
X-Received: by 10.157.61.131 with SMTP id l3mr395053otc.18.1484076641272;
        Tue, 10 Jan 2017 11:30:41 -0800 (PST)
In-Reply-To: <e779f1ca-8f05-7eda-72c8-89a9a5215c62@wanadoo.fr>
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:30470
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30470>

------=_Part_718_171003813.1484076640633
Content-Type: multipart/alternative; 
	boundary="----=_Part_719_1784432563.1484076640633"

------=_Part_719_1784432563.1484076640633
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Tuesday, January 10, 2017 at 1:49:05 PM UTC-5, Vicente J. Botet Escriba=
=20
wrote:
>
> Le 10/01/2017 =C3=A0 16:31, m.ce...@gmail.com <javascript:> a =C3=A9crit =
:
>
>
> W dniu wtorek, 10 stycznia 2017 13:49:00 UTC+1 u=C5=BCytkownik=20
> gmis...@gmail.com napisa=C5=82:=20
>>
>>
>>
>> On Tuesday, January 3, 2017 at 10:56:05 PM UTC+13, m.ce...@gmail.com=20
>> wrote:=20
>>>
>>> Hi,=20
>>>
>>>
> I'll try to create a first draft after I get some more comments w.r.t to=
=20
> exceptions.
> For sure baseline API must be exception-free.
> Do we really want to additionally support API that throws on error?
> I'm rather inclined to leave it out - similarly as in to_chars/from_chars=
..
> =20
>
>>
>> I hope this post assists you with your proposal. My suggestions are for=
=20
>> your proposal to look something like this:
>>
>> In <utility> I think add:
>>
>> bool template<typename E, typename V> is_enum( V ev )
>> {
>>  // compiler magic:
>>  // Calling this routine causes the compiler to generate or a call a=20
>> routine
>>  // that returns true if the value ev matches one of the enum E's
>>  // values. otherwise false.
>> }
>>
>
> 'is_enum' name is already used in type_traits header.
> Also is_enum seems redundant to me, since to_enum already reports
> if convertion succeeded instead of:
> if (is_enum<MyEnum>(139))
>
> you could write:
> if (to_enum<MyEnum>(139).is_valid)
>
> or even:
> if (to_enum<MyEnum>(139))
> if we add explicit bool convertion operator for to_enum_result.
>
>
> I believe we need two checking functions:
> * is_enumerator : checks if the explicit conversion from the integer is=
=20
> one of the explicit enumerators
> * is_in_enum_range: checks if the integer is in the range of valid values=
..=20
> This is the precondition of the static_cast.
>
> IIUC when the underlying type is explicit, the range of values are the=20
> range of the underlying type. However when the underlying type is implici=
t=20
> the range goes from the min to the max of the values of the enumerators.
>

Right, but `is_enumerator` is a functional superset of `is_in_enum_range`.=
=20
Do people really need to ask *only* if a value is in the range of an=20
enumerator?

--=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/24e58aad-ecbc-4c83-a21b-de56ea4c1db0%40isocpp.or=
g.

------=_Part_719_1784432563.1484076640633
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, January 10, 2017 at 1:49:05 PM UTC-5, =
Vicente J. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"m=
argin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"=
>
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div>Le 10/01/2017 =C3=A0 16:31,
      <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"H0=
6U3IL9BQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#3=
9;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;"=
>m.ce...@gmail.com</a> a =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote type=3D"cite">
      <div dir=3D"ltr"><br>
        W dniu wtorek, 10 stycznia 2017 13:49:00 UTC+1 u=C5=BCytkownik
        <a>gmis...@gmail.com</a> napisa=C5=82:
        <blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex">
          <div dir=3D"ltr"><br>
            <br>
            On Tuesday, January 3, 2017 at 10:56:05 PM UTC+13, <a>m.ce...@g=
mail.com</a> wrote:
            <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:=
1px;border-left-style:solid">
              <div dir=3D"ltr">Hi,
                <div><br>
                </div>
              </div>
            </blockquote>
          </div>
        </blockquote>
        <br>
        <div>I&#39;ll try to create a first draft after I get some more
          comments w.r.t to exceptions.</div>
        <div>For sure baseline API must be exception-free.</div>
        <div>Do we really want to additionally support API that throws
          on error?</div>
        <div>I&#39;m rather inclined to leave it out - similarly as in
          to_chars/from_chars.</div>
        <div>=C2=A0</div>
        <blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex">
          <div dir=3D"ltr">
            <div><br>
            </div>
            <div>I hope this post assists you with your proposal.=C2=A0My
              suggestions are for your proposal to look something like
              this:</div>
            <div><br>
            </div>
            <div>In &lt;utility&gt; I think add:</div>
            <div><br>
            </div>
            <div>bool template&lt;typename E, typename V&gt; is_enum( V
              ev )</div>
            <div>{</div>
            <div>=C2=A0// compiler=C2=A0magic:</div>
            <div>=C2=A0// Calling this routine causes the compiler to
              generate or a call a routine</div>
            <div>=C2=A0// that returns true if the value ev matches one of
              the enum E&#39;s</div>
            <div>=C2=A0// values. otherwise false.</div>
            <div>}</div>
          </div>
        </blockquote>
        <div><br>
        </div>
        <div>&#39;is_enum&#39; name is already used in type_traits header.<=
br>
        </div>
        <div>Also is_enum seems redundant to me, since to_enum already
          reports</div>
        <div>if convertion succeeded instead of:</div>
        <div>
          <div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
              <div><span style=3D"color:#008">if</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">(</span><span style=3D"color:#000=
">is_enum</span><span style=3D"color:#660">&lt;</span><span style=3D"color:=
#606">MyEnum</span><span style=3D"color:#660">&gt;(</span><span style=3D"co=
lor:#066">139</span><span style=3D"color:#660">))</span></div>
            </code></div>
          <br>
        </div>
        <div>you could write:</div>
        <div>
          <div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
              <div><span style=3D"color:#008">if</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">(</span><span style=3D"color:#000=
">to_enum</span><span style=3D"color:#660">&lt;</span><span style=3D"color:=
#606">MyEnum</span><span style=3D"color:#660">&gt;(</span><span style=3D"co=
lor:#066">139</span><span style=3D"color:#660">).</span><span style=3D"colo=
r:#000">is_valid</span><span style=3D"color:#660"><wbr>)</span></div>
            </code></div>
          <br>
        </div>
        <div>or even:</div>
        <div>
          <div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
              <div><span style=3D"color:#008">if</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">(</span><span style=3D"color:#000=
">to_enum</span><span style=3D"color:#660">&lt;</span><span style=3D"color:=
#606">MyEnum</span><span style=3D"color:#660">&gt;(</span><span style=3D"co=
lor:#066">139</span><span style=3D"color:#660">))</span></div>
            </code></div>
          if we add explicit bool convertion operator for
          to_enum_result.</div>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
    </blockquote>
    I believe we need two checking functions:<br>
    * is_enumerator : checks if the explicit conversion from the integer
    is one of the explicit enumerators<br>
    * is_in_enum_range: checks if the integer is in the range of valid
    values. This is the precondition of the static_cast.<br>
    <br>
    IIUC when the underlying type is explicit, the range of values are
    the range of the underlying type. However when the underlying type
    is implicit the range goes from the min to the max of the values of
    the enumerators.<br></div></blockquote><div><br>Right, but `is_enumerat=
or` is a functional superset of `is_in_enum_range`. Do people really need t=
o ask <i>only</i> if a value is in the range of an enumerator?<br></div></d=
iv>

<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/24e58aad-ecbc-4c83-a21b-de56ea4c1db0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/24e58aad-ecbc-4c83-a21b-de56ea4c1db0=
%40isocpp.org</a>.<br />

------=_Part_719_1784432563.1484076640633--

------=_Part_718_171003813.1484076640633--

.
