220 30175 <2998762.etaySSRi7N@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: enum_cast proposal
Date: Tue, 03 Jan 2017 13:56:30 -0200
Lines: 53
Approved: news@gmane.org
Message-ID: <2998762.etaySSRi7N@tjmaciei-mobl1>
References: <efdf2357-00a6-408a-8772-12f99135a880@isocpp.org> <1483532086.2yCkjVBYWJ@tjmaciei-mobl1> <bb835a83-0f69-4a76-97df-581c2a2ae8d8@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
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1483459003 30240 195.159.176.226 (3 Jan 2017 15:56:43 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 3 Jan 2017 15:56:43 +0000 (UTC)
User-Agent: KMail/5.3.3 (Linux/4.8.13-1-default; KDE/5.28.0; x86_64; ; )
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBMUTV7BQKGQEZ6QIFQI@isocpp.org Tue Jan 03 16:56:34 2017
Return-path: <std-proposals+bncBCB4TK757YBRBMUTV7BQKGQEZ6QIFQI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wj0-f198.google.com ([209.85.210.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBMUTV7BQKGQEZ6QIFQI@isocpp.org>)
	id 1cORRv-0006OS-5C
	for gclcip-std-proposals@m.gmane.org; Tue, 03 Jan 2017 16:56:31 +0100
Original-Received: by mail-wj0-f198.google.com with SMTP id iq1sf50452648wjb.1
        for <gclcip-std-proposals@m.gmane.org>; Tue, 03 Jan 2017 07:56:35 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:user-agent:in-reply-to:references
         :mime-version: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=tsN/6QbintzU+m13NQUEsJTknUgb0LBSFRDoQMF5qpU=;
        b=oQCnQyUO0e47sOoWFUW0iiLdj9w6P8mGQjs+eTcB+ZEdZhSpM91toBouYumW/nLY8G
         /dRF4hyH30s+82y5TFvPhPpfB7dUyBPOu/wMym+Q9guYfQs1fG/HBa/A5klx7lLcjl5v
         8lF3eWkxhp0yUj4jT4+xswJVCSJCUYz2R6oxROsMXbO5fmFkx6wNsr7V8lv5+y1iVxhc
         2bcK6DRcgwdhhJK/OsOmzfm469YC8BdAckC+nwM2x2+37Tf3RmIf5K2XFJOzX5shRlA2
         Wt/uQ2PVOr3oaIQrK55EA/Q3ZPF8nMST5bLmVlQrWSbVML475FsqyKAyvJW2VvFwIoYG
      
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:user-agent
         :in-reply-to:references:mime-version: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=tsN/6QbintzU+m13NQUEsJTknUgb0LBSFRDoQMF5qpU=;
        b=mXnVgjwkIW1rJM/l736TdwFIfYz54HET6o4l7EpLzvvcAN+1nwTTA1G1NGCyfcNUUE
         Ca84UiQyZ+Mwig6NzQZQ4SKlpgFl5dKQiU00BtomG94eV4KHWI7dxoyKLvS/kKooxZSi
         OXYJgDcbNUXlEHg+rpsUQ2mmixDiQ1Q718VPdakvlMJvTg2NA7jM92xiYmo6KpDw01Ip
         CYthcO1JB0hmbSTbFHegaYuiP5lkE7Ja6x3Q9vJIkqOrRciL/lbv1nMmVyUoa3QEIAjn
         xAod7Nu7X8OQTUDEOrdAwubXf7C4clnpX4Fyfhf8YTzEXUG4H8Z09ENyFfylveXDIjWz
  
X-Gm-Message-State: AIkVDXInx5J+62zpRh80iXJ7BjEMBRl3GnqbUKdnIjxNk/cvS+cwGT0WPC8kIrbWa2fHvw==
X-Received: by 10.28.23.207 with SMTP id 198mr1568621wmx.0.1483458995301;
        Tue, 03 Jan 2017 07:56:35 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.157.71 with SMTP id g68ls5972183wme.27.canary-gmail; Tue,
 03 Jan 2017 07:56:34 -0800 (PST)
X-Received: by 10.194.99.38 with SMTP id en6mr54696013wjb.184.1483458994240;
        Tue, 03 Jan 2017 07:56:34 -0800 (PST)
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [78.47.120.188])
        by mx.google.com with ESMTP id b197si74017617wme.159.2017.01.03.07.56.34
        for <std-proposals@isocpp.org>;
        Tue, 03 Jan 2017 07:56:34 -0800 (PST)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) client-ip=78.47.120.188;
Original-Received: from tjmaciei-mobl1.localnet (unknown [187.34.234.250])
	by gondolin.macieira.info (Postfix) with ESMTPSA id 34DBA11B7E9
	for <std-proposals@isocpp.org>; Tue,  3 Jan 2017 07:56:33 -0800 (PST)
In-Reply-To: <bb835a83-0f69-4a76-97df-581c2a2ae8d8@isocpp.org>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
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:30175
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30175>

On ter=C3=A7a-feira, 3 de janeiro de 2017 07:06:10 BRST m.cencora@gmail.com=
 wrote:
> Compiler should synthesize a function like below:
>=20
> optional<color> enum_cast(int x)
> {
>     switch(x)
>     {
>         case red:
>         case green:
>         case blue:
>             return static_cast<color>(x);
>         default:
>             return nullopt;
>     }
> }

How do you know whether a use of enum_cast is compile-time or whether it is=
=20
runtime?

static_cast is always compile time and always succeeds or produces a=20
compilation error. Therefore, checking at runtime is unnecessary.

dynamic_cast is almost always runtime and its result needs to be checked at=
=20
runtime.

Also, where did that optional come from? If it's going to use optional, the=
n=20
it needs to be a library feature.

> Of course it could implement it more efficently (as range check instead o=
f
> switch if all enumerators are consecutive integers).

One would expect the compilers to be smart enough to do that with a switch=
=20
block that is contiguous. Still, QoI issue.

--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--=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/2998762.etaySSRi7N%40tjmaciei-mobl1.

.
