220 30215 <87adf165-dd56-e16f-e4ab-c14931921540@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: Re: enum_cast proposal
Date: Wed, 4 Jan 2017 08:13:30 +0100
Lines: 48
Approved: news@gmane.org
Message-ID: <87adf165-dd56-e16f-e4ab-c14931921540@wanadoo.fr>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org>
 <1d5db671-8ee9-49dc-937d-10a20f48fe73@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1483514021 22520 195.159.176.226 (4 Jan 2017 07:13:41 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 4 Jan 2017 07:13:41 +0000 (UTC)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0)
 Gecko/20100101 Thunderbird/45.6.0
Cc: m.cencora@gmail.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDH67CONY4PBBGWBWLBQKGQEN67YYTQ@isocpp.org Wed Jan 04 08:13:34 2017
Return-path: <std-proposals+bncBDH67CONY4PBBGWBWLBQKGQEN67YYTQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wj0-f199.google.com ([209.85.210.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDH67CONY4PBBGWBWLBQKGQEN67YYTQ@isocpp.org>)
	id 1cOflH-00049H-8n
	for gclcip-std-proposals@m.gmane.org; Wed, 04 Jan 2017 08:13:27 +0100
Original-Received: by mail-wj0-f199.google.com with SMTP id hb5sf114285730wjc.2
        for <gclcip-std-proposals@m.gmane.org>; Tue, 03 Jan 2017 23:13:31 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:cc:from:message-id:date:user-agent
         :mime-version:in-reply-to:content-transfer-encoding
         :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=3hgLliZVuWrfxI1f07v80C45Ii6pT0RdtKE9ONfWLEw=;
        b=I6EVEZPVXXv2JO9mZpV1cJNJfLFlDDIQ3nXewZyEILizit0ti8qNqgGy4hQdz1vpre
         D/HxuyYA/wQUg47XGyFKSblxU7gM2HqKDWxmGl+KSPAcP81CMcwnfviyvNO9nxb+JCqQ
         EogD5VRNMW7jeCYXwgneOqGrnI6Fz2LNP7fx2abJfsQhUtoeSDqOT88gNnHyfbN0NhVK
         ilFh4HaHzLRdtfQD8H6DmuY2+OEihuW2VArg9ju9kEtfxLTj33J8b9kY3pZoV8ph6Ozu
         9j8jTizS+ErPkFi+8CkVMOFf2SdLg921srPuDSq9Geavn77flMZmV47zC7vnv4VNweLs
   
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:cc:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-transfer-encoding
         :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=3hgLliZVuWrfxI1f07v80C45Ii6pT0RdtKE9ONfWLEw=;
        b=eiUO3NeCgSOhad380jl7XDxkniZPPN7d10Td2nQFCexVICIVSLYXINE25OR9cvNqmE
         ZxTo+px0NmRqxIwgHGhEgEk7tnUOkKH4FdnyjABQgTGwtoeQMYMWoxJ8C7bOAyxYGbV5
         fvd23DFBnl1WyAQd36yBj0ynSBjVmxJCvFhijDNbZRky+AaCpFGki0r9RxSGeSVyV7Ul
         9HRvvIDXfp3KSPgks/NZ+Q/Mp/RhvtZ2/Hjy4O5ss1/dBFcymojQsOEubkWvlUlCfLPH
         wgSvA/aXPnSzzXXvHXcUetBz+5vBO1dzlAA24oZadqESBXQXRk6D9qa0RsCHIxwewAV 
X-Gm-Message-State: AIkVDXKo9nJkAYgZwegJtBq12aDfEpaBsvhBFVtPqOhB3x5klyv5P5zHX21yux8RZU8LJw==
X-Received: by 10.28.26.72 with SMTP id a69mr1581585wma.4.1483514011626;
        Tue, 03 Jan 2017 23:13:31 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.45.80 with SMTP id t77ls80106wmt.25.canary-gmail; Tue, 03
 Jan 2017 23:13:30 -0800 (PST)
X-Received: by 10.194.71.17 with SMTP id q17mr66297298wju.180.1483514010412;
        Tue, 03 Jan 2017 23:13:30 -0800 (PST)
Original-Received: from smtp.smtpout.orange.fr (smtp09.smtpout.orange.fr. [80.12.242.131])
        by mx.google.com with ESMTPS id 12si76641269wms.74.2017.01.03.23.13.30
        for <std-proposals@isocpp.org>
        (version=TLS1 cipher=AES128-SHA bits=128/128);
        Tue, 03 Jan 2017 23:13:30 -0800 (PST)
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 ([92.139.156.24])
	by mwinf5d69 with ME
	id U7DV1u00K0Xrduc037DVEg; Wed, 04 Jan 2017 08:13:30 +0100
X-ME-Helo: imac-de-vicente-botet-escriba.home
X-ME-Auth: dmljZW50ZS5ib3RldEB3YW5hZG9vLmZy
X-ME-Date: Wed, 04 Jan 2017 08:13:30 +0100
X-ME-IP: 92.139.156.24
In-Reply-To: <1d5db671-8ee9-49dc-937d-10a20f48fe73@isocpp.org>
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:30215
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30215>

Le 04/01/2017 =C3=A0 00:48, gmisocpp@gmail.com a =C3=A9crit :
>
> Just considering my earlier make_enum comment further, The ultimate=20
> minimum for C++ is surely this?:
>
> traffic_light light{}; // whatever default.
> bool guaranteed_success =3D std::can_cast_enum<traffic_light>(x);
> if (guaranteed_success)
>  light =3D reinterpret_cast<traffic_light>(x);
> // else error condition.
>
> It separates the validity check from the conversion and then you can=20
> build whatever on that, i.e. assign, atomic assign, etc.
> This seems more C++ like, but forgets C, which probably people feel is=20
> not a concern anyway.
> But other wise some special C and C++ syntax like=20
>  can_cast_enum(traffic_light, x) would seem to cover both languages if=20
> that's desirable.
Yes, this is the good interface :)

I'm all for a proposal of this minimal interface, even if I would add a=20
enum_cast synonym of static_cast.
It is clear from the previous code that there is no problem with the=20
cast and using the same name would surely help

     const traffic_light light =3D (std::can_enum_cast<traffic_light>(x))=
=20
? std::enum_cast<traffic_light>(x)  :=20
throw_bad_enum_cast<traffic_light>(x);

Note that throw_bad_enum_cast is not proposed. It is only and example to=20
show the interface allows the use of safe conversions expressions.

We could see later what can be built on top of it and what could be on=20
the standard.

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/87adf165-dd56-e16f-e4ab-c14931921540%40wanadoo.f=
r.

.
