220 33530 <aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18@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 13:33:25 +0200
Lines: 144
Approved: news@gmane.org
Message-ID: <aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18@wanadoo.fr>
References: <6a2c32ed-99b5-4cc5-86a5-ee3cc07567a3@isocpp.org>
 <2570492.NpxuI0RVu0@tjmaciei-mobl1>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------456D88599976B7BA492A1A36"
X-Trace: blaine.gmane.org 1501673612 24513 195.159.176.226 (2 Aug 2017 11:33:32 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 2 Aug 2017 11:33:32 +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, Thiago Macieira <thiago@macieira.org>
Original-X-From: std-proposals+bncBDH67CONY4PBBCXRQ3GAKGQEOBPH56Y@isocpp.org Wed Aug 02 13:33:28 2017
Return-path: <std-proposals+bncBDH67CONY4PBBCXRQ3GAKGQEOBPH56Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f69.google.com ([209.85.215.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDH67CONY4PBBCXRQ3GAKGQEOBPH56Y@isocpp.org>)
	id 1dcru2-0005yW-0W
	for gclcip-std-proposals@m.gmane.org; Wed, 02 Aug 2017 13:33:26 +0200
Original-Received: by mail-lf0-f69.google.com with SMTP id m86sf10288024lfi.12
        for <gclcip-std-proposals@m.gmane.org>; Wed, 02 Aug 2017 04:33:32 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1501673612; cv=pass;
        d=google.com; s=arc-20160816;
        b=fwnQUlhpEre6LUZ5PKf6ZI57UTB9+TpZk49Xfr/9xvk4PoxT8MOkkyImIK6Qpr+QAg
         ZmsK7OxWoYFgx9iWcOYzvW/KwX3X/PLEsyXhkuxsQoNiweUD6anipriuuAqLVTCnZXwa
         sTE/I3Kv1PqNXID+0XS44rahxCL8R7P20PwRI33k4mAjxgEpTHCX//M2sUvT1OG3st5R
         hAvwf1htdppnQbDJ1OgZb2ynkaX90+9As1y+lW55p9xayG2gUqyjCI1cqQGl1zxwLlmo
         ZC5DgCa8FjC3IJuEbjwiMRoHY824VwybSTN0rdAs2O682rhcmHy/KKkBRVrep0VPyCzJ
         rmkw==
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=HXcw1thi0PFLbNsu6u6GuvDS1qngasElAYEnmb+NGt4=;
        b=u48t+toVJMhXlniarAawRS61h9hJltoGSBnBz7sGl27djhJoA/ksBp0T2jP+hJd2xI
         SnFw8Vb9e3g7f9d4JramYzmh3sq7GyO0jor2pRVAOarGvwm2oQ2QBMeTkr+e97DvvJcs
         j2ej0qixAfu9xEeTuQff8dubYTUhD+1U4AoeAjJ0Ax6sBF1ORnowTSnRtmljMwRzjBRp
         st4li4pWbCPdtBKiitbaIgdlvUmNlZOPG7wUpOBUEdG7mYzLiex5mjG+xhImSvqVmPtB
         JAQm87dNkVJFHNz214ZOCQzz/bI+fgFfY2sDiXCBh8PQcVPddBnq1GAK+plWMHwf480U
         E/8w==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=neutral (google.com: 80.12.242.131 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=HXcw1thi0PFLbNsu6u6GuvDS1qngasElAYEnmb+NGt4=;
        b=OHNdu55zU4fz3FZev3V3YamatD1aIF0p1eSxNlBZhjIvVOrvSQJ6BO9om8SPE5s5gi
         x7dn3SqBfaIO4Kn/MVophw3ZgAw5Ha+TtFjBlpdaZz5lYWIAbocKBRSjKCg3seLXqk3m
         XoqpHXYPVF9cfT5MRBygrthMlrqKLTz+hxdMoV/fx91MHGrGsXwsE+ObzjZnbukcU3ks
         5oTXZ/Emz1jXZYPO8nzFT83nw8HkrYMHLZj4uqidasvaJH2nXZAuKT0DZGIUaEIgEhay
         NF7KIjIGCi4rC/V0L+PTM+hndifkMbvt9wtByXqyxUWJM5JsPuROucrgaqfHUstWL1sH
         2wvQ==
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=HXcw1thi0PFLbNsu6u6GuvDS1qngasElAYEnmb+NGt4=;
        b=Le0SEGiTq1wK72oMgPj6mhrbastDeLtd3Xi+ortWb6o0cgAtqOWDftd6ZvvicGrq/C
         taExngBQL3Y265fzBIsa4nK220XcwWhbHaCuZ+5c/PuLvahI97cKgz7MzhXYuJcB4hAV
         yq9h+hrDabCmXoZoXHCG4jnm1RMe8+2wWk7b3g6DdIeyD5hgbjh7LsyImNUrAaBf3Uc6
         Nz8LtHNVrgZBUjbaDdKxUuw1O0U/InXjIC1ly2hXiX6lP4WNHvYZnaQxWZm52W26edZz
         jVV+ifY6AO9vN/r2iObZZVwIMBfg8LovkIy87KyJKD4tOqjeviGsaazGA5IT9N8HbWsy
         w 
X-Gm-Message-State: AIVw112C0HkKjxZdPudf1p9CMzcZOpHktQkwTpjWa+8b8K8sAUnpz+K2
	13a2hTfRLmJ18g==
X-Received: by 10.25.22.32 with SMTP id m32mr2417627lfi.37.1501673612222;
        Wed, 02 Aug 2017 04:33:32 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.156.195 with SMTP id f186ls126121wme.0.experimental-gmail;
 Wed, 02 Aug 2017 04:33:30 -0700 (PDT)
X-Received: by 10.223.137.137 with SMTP id x9mr16516790wrx.242.1501673610033;
        Wed, 02 Aug 2017 04:33:30 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1501673609; cv=none;
        d=google.com; s=arc-20160816;
        b=vLFHXadirGROKwNBSY/csJVhVAmRlq6cobg2mIxtINabU8t6Y4pttoLx7Fbqoytt5O
         kYnEP+gwkSDZmDsPGSc5vkYFS5Iva1PyAcK52QEXn7nLLGfU6ODJCe+eg8EVqOwtt7Ai
         1febhNrojVjByGnSUndcdv/nTTToxqwwx2rGIWucpbqqEJLBGl6nAB7YbnmIWSG6WAyx
         y2fjDkSdxF7FiLr+2Yfc6TSi3SvgvJpnWFpMf2qIlNKTlK9DA4Mto1m67gZy0ArDe5Tp
         sZT6Z+zkbTanZldSiT8yTAd14EghVqojn/RopfH0DXptjE3w8inzn5QydKWsTEw8cy7z
         pBZA==
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=qav63OtgAE+WhCPUVZkMMjyvNgUZQezqw7vooXekrX8=;
        b=cQt+ZoxNWXFMY1E/3nKRJ13e9f95LXlsLB6It+o3yOB/kkvNn6NS0UwuLAW3c/+6qt
         qZu1eHKs+bYbv7b2z6IIb1J6YYHeBZLoyF3A672bx8tdTZS4gvHBgTQj6mha+DLQUZUm
         ga/ujJEnQ4aaIs3B7Yq23yUOX3eJGvd+AzWmgUMoFyMFD31efZy0jSZpkxA6O5EjDdQ0
         IWqwMW7lDcP6pwYllCqDgD7nWA5iM9h8FNmMjEud0CNfSQqqUfxdF7Y7SOjWWoFUv5wj
         E6mtxYeVnezu8jralY4/m+LAyMJskGacPlTFXLcV8c5PmElhh2TO6/Bhu5HfQFXu9kWA
         AGGQ==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=neutral (google.com: 80.12.242.131 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 (smtp09.smtpout.orange.fr. [80.12.242.131])
        by mx.google.com with ESMTPS id b7si3116078wma.65.2017.08.02.04.33.29
        for <std-proposals@isocpp.org>
        (version=TLS1 cipher=AES128-SHA bits=128/128);
        Wed, 02 Aug 2017 04:33:29 -0700 (PDT)
Received-SPF: neutral (google.com: 80.12.242.131 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) client-ip=80.12.242.131;
Original-Received: from imac-de-vicente-botet-escriba.home ([86.229.176.71])
	by mwinf5d84 with ME
	id sBZT1v00N1YoQGN03BZTM7; Wed, 02 Aug 2017 13:33:29 +0200
X-ME-Helo: imac-de-vicente-botet-escriba.home
X-ME-Auth: dmljZW50ZS5ib3RldEB3YW5hZG9vLmZy
X-ME-Date: Wed, 02 Aug 2017 13:33:29 +0200
X-ME-IP: 86.229.176.71
In-Reply-To: <2570492.NpxuI0RVu0@tjmaciei-mobl1>
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.131 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:33530
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33530>

This is a multi-part message in MIME format.
--------------456D88599976B7BA492A1A36
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable

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 it=
s
>> 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=20
libraries that wrap other types to build opaque types.

I've as well used underlying_cast to static_cast the underlying value to=20
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.


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/aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18%40wanadoo.f=
r.

--------------456D88599976B7BA492A1A36
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 30/07/2017 =C3=A0 18:20, Thiago Macie=
ira
      a =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote type=3D"cite" cite=3D"mid:2570492.NpxuI0RVu0@tjmaciei-mobl1=
">
      <pre wrap=3D"">On Sunday, 30 July 2017 04:50:41 PDT <a class=3D"moz-t=
xt-link-abbreviated" href=3D"mailto:james.a.cooper@gmail.com">james.a.coope=
r@gmail.com</a> wrote:
</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">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 wrap=3D"">
Yes on the convenience, but "underlying_cast" is the wrong name because thi=
s=20
does not look like a regular cast.

Something like "std::underlying_value" might be better.

</pre>
    </blockquote>
    <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&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>
    <p><font size=3D"+1"><br>
      </font></p>
    <p><font size=3D"+1">Vicente</font><br>
    </p>
  </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/aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/aa4104f9-5a29-c1d9-22ac-1dfa9cad8d18=
%40wanadoo.fr</a>.<br />

--------------456D88599976B7BA492A1A36--

.
