220 33535 <CABPJVnSrvKQPXqRPDju8PnnXv_M6+3EuPCuqMkMb9QigC-6fTQ@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: John McFarlane <john@mcfarlane.name>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal: underlying_cast
Date: Wed, 02 Aug 2017 15:21:42 +0000
Lines: 188
Approved: news@gmane.org
Message-ID: <CABPJVnSrvKQPXqRPDju8PnnXv_M6+3EuPCuqMkMb9QigC-6fTQ@mail.gmail.com>
References: <6a2c32ed-99b5-4cc5-86a5-ee3cc07567a3@isocpp.org>
 <2570492.NpxuI0RVu0@tjmaciei-mobl1> <aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18@wanadoo.fr>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="94eb2c0defc0dd65860555c6d24f"
X-Trace: blaine.gmane.org 1501687314 8327 195.159.176.226 (2 Aug 2017 15:21:54 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 2 Aug 2017 15:21:54 +0000 (UTC)
To: std-proposals@isocpp.org, Thiago Macieira <thiago@macieira.org>
Original-X-From: std-proposals+bncBDS7B7WQUYOBBEW4Q7GAKGQE4CEO64Y@isocpp.org Wed Aug 02 17:21:50 2017
Return-path: <std-proposals+bncBDS7B7WQUYOBBEW4Q7GAKGQE4CEO64Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f197.google.com ([209.85.128.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDS7B7WQUYOBBEW4Q7GAKGQE4CEO64Y@isocpp.org>)
	id 1dcvT4-0001wN-0C
	for gclcip-std-proposals@m.gmane.org; Wed, 02 Aug 2017 17:21:50 +0200
Original-Received: by mail-wr0-f197.google.com with SMTP id x43sf6435713wrb.9
        for <gclcip-std-proposals@m.gmane.org>; Wed, 02 Aug 2017 08:21:56 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1501687316; cv=pass;
        d=google.com; s=arc-20160816;
        b=ejqzPlgppuPgOrxo0m/Yfn7tDsG4N4n3WC9pWGbAgKTnWaBfUItZheDpZlxNjKuahO
         ApDJ7kbOr0nCBJzma/9uhWoDJl+NygjBaA3bfW/Kq6M7E7vupMSyQ6FobMRIlCqn/loK
         MmlTc/5UbClZF4RAK65kQ0Fmj5EBWanqGbYAGRpQgLQNWPFAfv3ehj54LEX+jgadSa4T
         /3osLlqAOXJgs5OwwaOo9OczUZWau2IuU3XHUKgb0s0nuYynEMz8/EkS5iuR5KvyCRQe
         p7nWJ2ePYd4Is931Xd94Hpo4OnQ2eEXDQyQLWp/iaZANqr2ksp3Xrq36CMtGPpkyd7It
         DR1A==
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:to:subject:message-id:date
         :from:in-reply-to:references:mime-version:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=pFXkaeLnPcDDHgmYAwWLDFRlp1u+/eBgYszVuNx08do=;
        b=sojvFbfjOKpIrSZ8gu2fyu7mcgp8s9k9UiyxUfreLmRIoJgN8LP39K0gCa7mq1XG7o
         3SGuqGx+aJktaDo6jny9oQHSnfNuDXUsxtNSId44n1uvBZWT0T8kGLEEcGWExJE42+oF
         3IxYZwtF7Pm++TlTvm8c+JHju/L55N5p7XgxNAjAIT+Ub3peVHuT7hP3BFgz9iKjBDA3
         pVtagqx5XXKLBS8u0o0jjSxdrLs9SgMNu4ZQOkOO5aInHupImJEtB8Y0FV4c9Ryxi90n
         7/ZVnkuVTl94MnRziMbyoyygrsHBCsmBcOLIz6FUoFE0t7b8MAwt3dWbisFnSp3S7P3m
         1HuQ==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of mcfarlane.john@gmail.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=mcfarlane.john@gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:references:in-reply-to:from:date:message-id:subject: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;
        bh=pFXkaeLnPcDDHgmYAwWLDFRlp1u+/eBgYszVuNx08do=;
        b=A3QZVjL/0YmbEwU1s06pzlBWMYf8ZIpGN3ZuAe0j5As8HaE1WJ63HzfY6ANrZ4kVvZ
         D/yOQenQD+dtHzwVQWqOuI7gmG3J837gA3l7+uQyc9m+BuqaUFE0neOYJd8r4oR/bZFy
         9PxK/LZWpfq1QXNqn5AQm7kbKCl/95frD333AAZhYJDspJ0kkXAyAAsPZN6K/9jUY2wn
         F7WQWmjP77aCzVVE4Ym5auV8r9RUquJ/vVLoSm5HajGVuvXNnzRjc920Uu/MTkjgbQbB
         KuQQxzfd2Co35B4lYh8oXbL4y8zgHyFP+T7LcAurvNyRNOpxstzOCX5LioNVRtN145V7
         DYmw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to: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=pFXkaeLnPcDDHgmYAwWLDFRlp1u+/eBgYszVuNx08do=;
        b=VQ4CAwyIDGSvamClWdkBQNBkd6GtSJCiR/5Yfr8TBBIMEeEQfVMmDS8Rqr6Vr/LV9+
         XUBGsXNa6FSI+BpIoER3l+7v6zGPt/xSO0MtZcNDKJma0GhzkkAYwM+iX1UkT+Z8P9m+
         gI4F0EVOz9zqufI9At3VaEV/1x7oGs6/x3BybovPlvydizDaFiTCdrrATvXbbAOJ7J7i
         1ADiWYzuJ90k4LQjroIMqhMVmJIdCYR1+CvKP4PaOpFEPILSXRc3k3X/KQZ0/ugGpJVi
         ootiXvDCD67Hh3Za5MxOze8fOHLbtIahlWf8AzTzA3KE3X2fhxb2Tmhf97cplKLxQ8TF
         Ek0w==
X-Gm-Message-State: AIVw1111rR+h0E1DaQasPnmAgznvgEh9Gzc7iJ16g0BSh22y+jekJ94k
	oSRjZcFr38BkUw==
X-Received: by 10.28.87.198 with SMTP id l189mr237704wmb.8.1501687316245;
        Wed, 02 Aug 2017 08:21:56 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.145.1 with SMTP id t1ls804776wmd.2.canary-gmail; Wed, 02
 Aug 2017 08:21:53 -0700 (PDT)
X-Received: by 10.80.206.91 with SMTP id k27mr970274edj.20.1501687313852;
        Wed, 02 Aug 2017 08:21:53 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1501687313; cv=none;
        d=google.com; s=arc-20160816;
        b=WrSAqGXkBZ1gGFjLzpp50HjbS2hEtu/ETmVb8CdR/e8yhqaPC0R9UpNhG2EE4PcVXz
         esDQO4KBtFu0WTxT0JfzfCnTIQUbtDBT4+eQhen/ZY0Qu3PPrlqckBKyLPZOhvhBaI73
         DSbvHYzVexphkSAS+deF5426xy1ubCrlzJo9Mm/HQaOQly88zRBFtMgEmkfby4OmHkbA
         TB2Czg6m3Tb9txaCwxYyRVuYfy9v+T18tDfqV+8nX3Gbg6kZTJumzFmY5/teqUTTzRzJ
         +un2Ehh4jgcKlDydvUkRLBcmVTBE8itaKo7524tKnQ+z5NhvgPsfkqJ3ik9qabdH529l
         YZEg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:in-reply-to:references:mime-version
         :arc-authentication-results;
        bh=cUF2MYluYgC5e+SAfoBA1h1coNan4gIOYnrzTCo94Sc=;
        b=tHNIwapgNPKi0oJ6+TDjd3QLsmkQwoJS0+3CFYVYp1kI4FUWMLLABnHPRiWZQ1jmFY
         TNVimthtvBAjv66FGQ2cxCmqdtwxLcj024LyDjXuVBvtUOH7/To0WiDHF70cHyGekHOB
         QYrr2cvy+MKoqWNWiXiS8elKfBKJQyIgte91e5q9bBhx9KSD2CJWLDmHv+LnYGurL8ey
         lqlEig+Rvv7bJg9DsXs9rFF20ZDFa/hl8sw3+inVyZv1hNWsmRQgRpVeDluBh/ETAJ9q
         jvyTsxxL/DFXiD4hNBMvJkFjhUeohRBf+N9zzZMOLhXzEbVJTJsRAn6KQKhiDZId5WxS
         Yndw==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of mcfarlane.john@gmail.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=mcfarlane.john@gmail.com
Original-Received: from mail-wr0-f179.google.com (mail-wr0-f179.google.com. [209.85.128.179])
        by mx.google.com with ESMTPS id z13si10041705edj.291.2017.08.02.08.21.53
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 02 Aug 2017 08:21:53 -0700 (PDT)
Received-SPF: pass (google.com: domain of mcfarlane.john@gmail.com designates 209.85.128.179 as permitted sender) client-ip=209.85.128.179;
Original-Received: by mail-wr0-f179.google.com with SMTP id y43so20066429wrd.3
        for <std-proposals@isocpp.org>; Wed, 02 Aug 2017 08:21:53 -0700 (PDT)
X-Received: by 10.223.146.35 with SMTP id 32mr17276886wrj.76.1501687313160;
 Wed, 02 Aug 2017 08:21:53 -0700 (PDT)
In-Reply-To: <aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18@wanadoo.fr>
X-Original-Sender: john@mcfarlane.name
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of mcfarlane.john@gmail.com designates 209.85.128.179 as permitted
 sender) smtp.mailfrom=mcfarlane.john@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:33535
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33535>

--94eb2c0defc0dd65860555c6d24f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Wed, Aug 2, 2017 at 4:33 AM Vicente J. Botet Escriba <
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 PDT james.a.cooper@gmail.com wrote:
>
> C++ allows enums to have an underlying type specified. 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 <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 because t=
his
> 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
`chrono::duration::rep` to be the underlying type of `chrono::duration` or
it is something else?  Because if the former, then `to_rep` from P0675
serves a similar purpose.

> Vicente
>
> --
> 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/aa4104f9-5a2=
9-c1d9-22ac-1dfa9cad8d18%40wanadoo.fr
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/aa4104f9-5a=
29-c1d9-22ac-1dfa9cad8d18%40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>

--=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/CABPJVnSrvKQPXqRPDju8PnnXv_M6%2B3EuPCuqMkMb9QigC=
-6fTQ%40mail.gmail.com.

--94eb2c0defc0dd65860555c6d24f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<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.bot=
et@wanadoo.fr">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 soli=
d;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_8705335493861=
418200moz-txt-link-abbreviated" href=3D"mailto:james.a.cooper@gmail.com" ta=
rget=3D"_blank">james.a.cooper@gmail.com</a> wrote:
</pre>
      <blockquote type=3D"cite">
        <pre>C++ allows enums to have an underlying type specified. When se=
rialising
enum values it&#39;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 &quot;underlying_cast&quot; is the w=
rong name because this=20
does not look like a regular cast.

Something like &quot;std::underlying_value&quot; might be better.

</pre>
    </blockquote>
    </div><div text=3D"#000000" bgcolor=3D"#FFFFFF"><p><font size=3D"+1">I&=
#39;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&#39;ve as well used underlying_cast to static_ca=
st
        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&g=
t;<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;(underlyi=
ng(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 considere=
d, would anyone consider `chrono::duration::rep` to be the underlying type =
of `chrono::duration` or it is something else?=C2=A0 Because if the former,=
 then `to_rep` from P0675 serves a similar purpose. <br></div><blockquote c=
lass=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"><p><font size=
=3D"+1">
      </font></p><font size=3D"+1">Vicente</font><br>
   =20
  </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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18%=
40wanadoo.fr?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/aa4104f9-5a29-=
c1d9-22ac-1dfa9cad8d18%40wanadoo.fr</a>.<br>
</blockquote></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/CABPJVnSrvKQPXqRPDju8PnnXv_M6%2B3EuPC=
uqMkMb9QigC-6fTQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CABPJVnSrvKQPXq=
RPDju8PnnXv_M6%2B3EuPCuqMkMb9QigC-6fTQ%40mail.gmail.com</a>.<br />

--94eb2c0defc0dd65860555c6d24f--

.
