220 33538 <db80d22b-15d6-0995-fa22-3e99eb745269@wanadoo.fr> article
Path: news.gmane.org!.POSTED!not-for-mail
From: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal: underlying_cast
Date: Wed, 2 Aug 2017 19:54:08 +0200
Lines: 195
Approved: news@gmane.org
Message-ID: <db80d22b-15d6-0995-fa22-3e99eb745269@wanadoo.fr>
References: <6a2c32ed-99b5-4cc5-86a5-ee3cc07567a3@isocpp.org>
 <2570492.NpxuI0RVu0@tjmaciei-mobl1>
 <aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18@wanadoo.fr>
 <CABPJVnSrvKQPXqRPDju8PnnXv_M6+3EuPCuqMkMb9QigC-6fTQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------131504E697C54933521C39FB"
X-Trace: blaine.gmane.org 1501696455 4866 195.159.176.226 (2 Aug 2017 17:54:15 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 2 Aug 2017 17:54:15 +0000 (UTC)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0)
 Gecko/20100101 Thunderbird/52.2.1
To: std-proposals@isocpp.org, John McFarlane <john@mcfarlane.name>,
 Thiago Macieira <thiago@macieira.org>
Original-X-From: std-proposals+bncBDH67CONY4PBBQ5DRDGAKGQEKWGC5CY@isocpp.org Wed Aug 02 19:54:10 2017
Return-path: <std-proposals+bncBDH67CONY4PBBQ5DRDGAKGQEKWGC5CY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f71.google.com ([209.85.215.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDH67CONY4PBBQ5DRDGAKGQEKWGC5CY@isocpp.org>)
	id 1dcxqQ-0000oS-AZ
	for gclcip-std-proposals@m.gmane.org; Wed, 02 Aug 2017 19:54:06 +0200
Original-Received: by mail-lf0-f71.google.com with SMTP id s12sf12448240lfs.8
        for <gclcip-std-proposals@m.gmane.org>; Wed, 02 Aug 2017 10:54:12 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1501696452; cv=pass;
        d=google.com; s=arc-20160816;
        b=vcm0pYB0XHognX+RgDn7ztUpNl+1wDXSzH6FT0CoNKxJb0gsvrKU/DMgEbNIypJMCU
         cy6if+/PErJu998xCl81TBsGpPFIbgZg2piKGmC2TE6hgLYuXbc1M1R6VgCWZkjMNlk+
         6MlTRg39vR4L0E4IuBA4LSVxaQMHiq0XWdc9+Aq81VqooBTQaFgVRSQkN9XdfPaOsmQb
         tTXsbPpxmKQKvLOkpukvqb5EXBgZ3Vt0XE8ssdseG6E0m9t2NykakQaM+QZp50cYs7ne
         XEVwuJRVEfeKvpDNCA6BBhsgGHlmP9G0u1JpwD7b46S3WzjLGvS6RAerBb+enued3luM
         MklQ==
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:content-language
         :in-reply-to:mime-version:user-agent:date:message-id:from:references
         :to:subject:arc-authentication-results:arc-message-signature
         :dkim-signature:arc-authentication-results;
        bh=dQ6ZylnCqkcti9mPBg/mvabXkjnUJ4xVVs8++4Wtmpo=;
        b=v8GNJfhDg4JnUn96hYPb/U1XjrnDSadjXKdXM+LBh6+StpOrLOoxSJb/GcUw7XCOXe
         EADQLw7fxGcbym9lOJZEfECsmO40Cw3YJV8z4rz5KpbPeZ0nYTJxpkVH97+Yu/k/L7HS
         L/JeQBWskfKD9k8P4HJpJaRxvAdOFUS97cC721ssW++hVvoIMEwC9TKp5VQxcmOUCLkq
         +B2edm2JqGcvO3rv87tlqGxEAUosjVpE3tsMeezfCIY4RhaE0hjvTb13X1iWI/LTYGUO
         T8GmD5xhmcDxTEtcUTYomszs1ztDIaHPjkdW8sZdGieJn6avbJcqja+FRv12SP8FH3ch
         c+mA==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=neutral (google.com: 80.12.242.132 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) smtp.mailfrom=vicente.botet@wanadoo.fr
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:content-language:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=dQ6ZylnCqkcti9mPBg/mvabXkjnUJ4xVVs8++4Wtmpo=;
        b=CFDIkzTN1+ump4Vyx8egJDsWoQaiD0aEDKS6O6Qoe+IJ0pvlGvRqvP0PP+zBfi/df9
         YHYRb5YD/4tESznLqmhclFqfgbKYZjSc666sbHfHDox49mcwIj6JS1bktc0Yz6y6nT3W
         agj7YMyo9YkT6PmJymfj8jBnMYJuTDi7dQpQv3L2xL7JPs2gdARndBlfS4SGPzkjuSZI
         s8UN90gt6Q3pnyGrdhustAZps8Ifi/+MQsCq1Sfe5FL72JJJoSkfu8BgFyV2t8Crr6KO
         rFxQgHqjGh/XHMPmaOFH9u92H78lIFt0cNT6VoRSxicL9wrsD9EMavQMe+NxV4ZZfZQs
         +7eg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-language
         :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=dQ6ZylnCqkcti9mPBg/mvabXkjnUJ4xVVs8++4Wtmpo=;
        b=eJmBKAI9E+CAk/LAKahI7a4Suh+eyHD6rUDkoK6h/baEl5480TliEUbGBj81DDqEdt
         2oFAb+ZZ4Vx75Xcu7YwRCJtNnQCvPhkIlKxBo0DENhDdzXej1fGpqnVJevFkuwzYoRht
         oeHOWiigOkY96ecsUa1nmW2gUmG+ykevtE9VOjjrht6h8a03lEjE/vUCg8P7TGUdrT4h
         joLs1rj0fCfT2Zky2fugQD+r80dRfMjZSKWykAqBzDYc+HSHIhxOnwBKOrsafNdBfVeU
         0zf4OBWvrbBJzFYzVYqvKo3OwBPkwZ8eyHeFubzM1jev5FKYGVb1uOiJUFK54XIVZBbT
         R 
X-Gm-Message-State: AIVw112GV8rbev8htdYUzo+k9r06FkgKcfvHbjz2cV8vfEy3OwvA5qj3
	FrnSfkT8KxcphA==
X-Received: by 10.46.5.213 with SMTP id 204mr2970500ljf.38.1501696452488;
        Wed, 02 Aug 2017 10:54:12 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.178.202 with SMTP id b193ls839925wmf.23.gmail; Wed, 02 Aug
 2017 10:54:10 -0700 (PDT)
X-Received: by 10.28.31.77 with SMTP id f74mr4426170wmf.149.1501696450881;
        Wed, 02 Aug 2017 10:54:10 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1501696450; cv=none;
        d=google.com; s=arc-20160816;
        b=qRjBgryoqVby1SFrDCoYvvGXIMhy1z+7OhK3BCsqeE2gyZuaVPEIU2ryYNccvwGM70
         lWhNzCTSTw1e7WJqrpQ7vZ9hz8QfiGBnmi9WeNWfRlGpndfwxL0PtTi6IGRxdrLfZ9A4
         r8Ay8k4gwF3dgDdns+JS5wmwBsZ6maBaANPMzhns3rtaMlRcTBYYJQzhcZwFOMB5yv3T
         MHylUdCWjCxsHudZVvaIiOYwzvG2Tl7/puCf7OSqAcBh6LZHYWn6h+d8XpqglhinTKrS
         ys3047z4z3R/S/fCdzS/XWBVULj9erwMrp+mJ6yEyhuUr4PfI+VkWIpAta2leHcIir4O
         XCvg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-language:in-reply-to:mime-version:user-agent:date
         :message-id:from:references:to:subject:arc-authentication-results;
        bh=TqB6lVqon1+7Zwq0Y+8DnutugjIn+ZJNxPjNZ+eEn/w=;
        b=mpBEL1NPjTgps3MmRM2lhHvDkg6JzAxUrtNw5Y5fE9VwSJQIq/gHwCScV4zueEoPg3
         NzGxCSg11ho7ZsFjLLwJQ80ZHcQZWdfd1/DbvDcgpi1kdRcZ/YcpXtfl88cssupcF2QE
         O87IoTBqU71jDNRHLTfGqXpIygsKS71m7PQBigWS2D7NgcF8/uQ4yjDs+0uD8JmCzwol
         bTajVU72Zv3UuEMHWz3ND2+QWvHMp2eoM/xA0g1j2OYyLr5AeWRcIHkVuiWHq6nNgm/8
         3aTEIcYYg9+hZAn2pSZdKWZw99C7YhnIZwCqDq4rqu1QbIszGR21m8dDrrAwLt85nWaA
         lfbg==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=neutral (google.com: 80.12.242.132 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) smtp.mailfrom=vicente.botet@wanadoo.fr
Original-Received: from smtp.smtpout.orange.fr (smtp10.smtpout.orange.fr. [80.12.242.132])
        by mx.google.com with ESMTPS id 79si3635719wms.259.2017.08.02.10.54.10
        for <std-proposals@isocpp.org>
        (version=TLS1 cipher=AES128-SHA bits=128/128);
        Wed, 02 Aug 2017 10:54:10 -0700 (PDT)
Received-SPF: neutral (google.com: 80.12.242.132 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) client-ip=80.12.242.132;
Original-Received: from imac-de-vicente-botet-escriba.home ([86.229.176.71])
	by mwinf5d20 with ME
	id sHu81v0091YoQGN03Hu9CB; Wed, 02 Aug 2017 19:54:10 +0200
X-ME-Helo: imac-de-vicente-botet-escriba.home
X-ME-Auth: dmljZW50ZS5ib3RldEB3YW5hZG9vLmZy
X-ME-Date: Wed, 02 Aug 2017 19:54:10 +0200
X-ME-IP: 86.229.176.71
In-Reply-To: <CABPJVnSrvKQPXqRPDju8PnnXv_M6+3EuPCuqMkMb9QigC-6fTQ@mail.gmail.com>
Content-Language: en-US
X-Original-Sender: vicente.botet@wanadoo.fr
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 80.12.242.132 is neither permitted nor denied by best guess
 record for domain of vicente.botet@wanadoo.fr) smtp.mailfrom=vicente.botet@wanadoo.fr
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:33538
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33538>

This is a multi-part message in MIME format.
--------------131504E697C54933521C39FB
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 02/08/2017 =C3=A0 17:21, John McFarlane a =C3=A9crit :
> On Wed, Aug 2, 2017 at 4:33 AM Vicente J. Botet Escriba=20
> <vicente.botet@wanadoo.fr <mailto:vicente.botet@wanadoo.fr>> wrote:
>
>     Le 30/07/2017 =C3=A0 18:20, Thiago Macieira a =C3=A9crit :
>>     On Sunday, 30 July 2017 04:50:41 PDTjames.a.cooper@gmail.com <mailto=
:james.a.cooper@gmail.com>  wrote:
>>>     C++ allows enums to have an underlying type specified. When seriali=
sing
>>>     enum values it's important to use the correct type.
>>>     This proposal is to add a utility function that casts an enum type =
to its
>>>     underlying value. This would make it easier to handle
>>>     enum types in function overloads for serialisation. For example:
>>>
>>>     template <typename T>
>>>     std::ostream& write(std::ostream& os, const T& v)
>>>     {
>>>          os << std::underlying_cast(v);
>>>          return os;
>>>     }
>>     Yes on the convenience, but "underlying_cast" is the wrong name beca=
use this
>>     does not look like a regular cast.
>>
>>     Something like "std::underlying_value" might be better.
>>
>     I've used underlying(v) to get the underlying value in some of my
>     libraries that wrap other types to build opaque types.
>
>     I've as well used underlying_cast to static_cast the underlying
>     value to another type that works with static cast
>
>         template <class U, class T>
>         U underlying_cast(T const& v)
>         {
>           return static_cast<U>(underlying(v));
>         }
>
>
>     This would be part of a library proposal for strong/opaque types.
>
> Question: If wrapped types are being considered, would anyone consider=20
> `chrono::duration::rep` to be the underlying type of=20
> `chrono::duration` or it is something else?  Because if the former,=20
> then `to_rep` from P0675 serves a similar purpose.
For me chrono::duration::rep is the underlying type an underlying type=20
is something that works not only for numeric types. Your to_rep<T>()(v)=20
function object is similar as underlying_cast<T>(v). Just wondering why=20
do you need a function object.



Vicente

--=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/db80d22b-15d6-0995-fa22-3e99eb745269%40wanadoo.f=
r.

--------------131504E697C54933521C39FB
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<html>
  <head>
    <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8=
">
  </head>
  <body text=3D"#000000" bgcolor=3D"#FFFFFF">
    <div class=3D"moz-cite-prefix">Le 02/08/2017 =C3=A0 17:21, John McFarla=
ne a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote type=3D"cite"
cite=3D"mid:CABPJVnSrvKQPXqRPDju8PnnXv_M6+3EuPCuqMkMb9QigC-6fTQ@mail.gmail.=
com">
      <div dir=3D"ltr">
        <div class=3D"gmail_quote">
          <div dir=3D"ltr">On Wed, Aug 2, 2017 at 4:33 AM Vicente J. Botet
            Escriba &lt;<a href=3D"mailto:vicente.botet@wanadoo.fr"
              moz-do-not-send=3D"true">vicente.botet@wanadoo.fr</a>&gt;
            wrote:<br>
          </div>
          <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text=3D"#000000" bgcolor=3D"#FFFFFF">
              <div class=3D"m_8705335493861418200moz-cite-prefix">Le
                30/07/2017 =C3=A0 18:20, Thiago Macieira a =C3=A9crit=C2=A0=
:<br>
              </div>
              <blockquote type=3D"cite">
                <pre>On Sunday, 30 July 2017 04:50:41 PDT <a class=3D"m_870=
5335493861418200moz-txt-link-abbreviated" href=3D"mailto:james.a.cooper@gma=
il.com" target=3D"_blank" moz-do-not-send=3D"true">james.a.cooper@gmail.com=
</a> wrote:
</pre>
                <blockquote type=3D"cite">
                  <pre>C++ allows enums to have an underlying type specifie=
d. When serialising
enum values it's important to use the correct type.
This proposal is to add a utility function that casts an enum type to its
underlying value. This would make it easier to handle
enum types in function overloads for serialisation. For example:

template &lt;typename T&gt;
std::ostream&amp; write(std::ostream&amp; os, const T&amp; v)
{
    os &lt;&lt; std::underlying_cast(v);
    return os;
}
</pre>
                </blockquote>
                <pre>Yes on the convenience, but "underlying_cast" is the w=
rong name because this=20
does not look like a regular cast.

Something like "std::underlying_value" might be better.

</pre>
              </blockquote>
            </div>
            <div text=3D"#000000" bgcolor=3D"#FFFFFF">
              <p><font size=3D"+1">I've used underlying(v) to get the
                  underlying value in some of my libraries that wrap
                  other types to build opaque types.</font></p>
              <p><font size=3D"+1">I've as well used underlying_cast to
                  static_cast the underlying value to another type that
                  works with static cast<br>
                </font></p>
              <p><font size=3D"+1">=C2=A0=C2=A0=C2=A0 template &lt;class U,=
 class T&gt;<br>
                  =C2=A0=C2=A0=C2=A0 U underlying_cast(T const&amp; v)<br>
                  =C2=A0=C2=A0=C2=A0 {<br>
                  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return static_cast&lt;U&gt=
;(underlying(v));<br>
                  =C2=A0=C2=A0=C2=A0 }<br>
                </font></p>
              <p><font size=3D"+1"><br>
                </font></p>
              <p><font size=3D"+1">This would be part of a library
                  proposal for strong/opaque types.<br>
                </font></p>
            </div>
          </blockquote>
          <div text=3D"#000000" bgcolor=3D"#FFFFFF">Question: If wrapped
            types are being considered, would anyone consider
            `chrono::duration::rep` to be the underlying type of
            `chrono::duration` or it is something else?=C2=A0 Because if th=
e
            former, then `to_rep` from P0675 serves a similar purpose. <br>
          </div>
        </div>
      </div>
    </blockquote>
    For me chrono::duration::rep is the underlying type an underlying
    type is something that works not only for numeric types. Your
    to_rep&lt;T&gt;()(v) function object is similar as underlying_cast&lt;T=
&gt;(v).
    Just wondering why do you need a function object.<br>
    <br>
    <br>
    <br>
    Vicente<br>
  </body>
</html>

<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/db80d22b-15d6-0995-fa22-3e99eb745269%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/db80d22b-15d6-0995-fa22-3e99eb745269=
%40wanadoo.fr</a>.<br />

--------------131504E697C54933521C39FB--

.
