220 9977 <e37e5153-7712-4890-a2af-88f73ef27ebc@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Matheus Izvekov <mizvekov@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Explicitly-defaulted enumeration operators
Date: Wed, 19 Mar 2014 15:14:00 -0700 (PDT)
Lines: 179
Approved: news@gmane.org
Message-ID: <e37e5153-7712-4890-a2af-88f73ef27ebc@isocpp.org>
References: <3B09C97E-7ADE-49ED-8C31-B5B41CD3DDE7@gmail.com> <781009e3-cd3c-4cb8-b034-b51a7c97c750@isocpp.org> <E797CAFE-4967-4881-870D-569BF15C757E@gmail.com> <10450602-fee9-48c4-9fa2-d000e434f5fb@isocpp.org> <6F532E62-C10A-404A-8F0D-662B7EA3D202@gmail.com> <24e85eaf-e67b-4a0b-acee-47d996d6f6ee@isocpp.org> <7F327393-B9EF-46EB-A40E-86F80EFEF5BD@gmail.com> <c17acc18-db6f-4233-b819-49bb623259dd@isocpp.org>
 <lgcl91$uln$1@ger.gmane.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_62_5262444.1395267240238"
X-Trace: ger.gmane.org 1395459611 24650 80.91.229.3 (22 Mar 2014 03:40:11 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 22 Mar 2014 03:40:11 +0000 (UTC)
Cc: mw_triad@users.sourceforge.net
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCOKZ27XTMNRBIUMWSMQKGQERZBRBWI@isocpp.org Sat Mar 22 04:40:21 2014
Return-path: <std-proposals+bncBCOKZ27XTMNRBIUMWSMQKGQERZBRBWI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f198.google.com ([209.85.214.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCOKZ27XTMNRBIUMWSMQKGQERZBRBWI@isocpp.org>)
	id 1WRCnE-0007Iq-M9
	for gclcip-std-proposals@m.gmane.org; Sat, 22 Mar 2014 04:40:20 +0100
Original-Received: by mail-ob0-f198.google.com with SMTP id wn1sf12125263obc.9
        for <gclcip-std-proposals@m.gmane.org>; Fri, 21 Mar 2014 20:40:19 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=QfgWCXQP3dY6E61V26LullgwH3V7oemJT7UE3sq0Q0Y=;
        b=LZ7muO5WRHKcMt8rznB4s1wOgXA3Z1pA+Rv1nCRJGc7Cedx0+BpyPlHT1VV/wwoR9x
         YpDE7WlDg//rap35DTY0laZvR4tekHQTEtjglVavOtFfOcGcM3CFBpyjzyZF181Rho9L
         OQZMkuEHRHKrUQKqHP1F1+hs86YuXLI/jqGFI8YLdNnmMW3qojTtWswhR13pmAJL+C/x
         ZAzXYGA7AuRTZZwfJml9j5hZ/IYHWL8NgRnGHjBXUJm4hLzjZksC6RyECrLlRy41rxRA
         pD5ezDnWYGriCCiZWAaJcp5LyifigVuGpngBnStjIOQ8Fo1dowsboDTXNJnH9ya48VbJ
         OHtw==
X-Gm-Message-State: ALoCoQnqL6zThaMqvu3cc1hDKWIH5gtr2G8JqnTDOycxzUMPisDWBBqTNCya+XHvsm3j04qXZ8SB
X-Received: by 10.182.51.200 with SMTP id m8mr7616132obo.16.1395459619636;
        Fri, 21 Mar 2014 20:40:19 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.89.136 with SMTP id v8ls873656qgd.17.gmail; Fri, 21 Mar
 2014 20:40:18 -0700 (PDT)
X-Received: by 10.236.197.39 with SMTP id s27mr11170754yhn.36.1395459618731;
        Fri, 21 Mar 2014 20:40:18 -0700 (PDT)
Original-Received: by 10.50.46.229 with SMTP id y5msigm;
        Wed, 19 Mar 2014 15:14:01 -0700 (PDT)
X-Received: by 10.182.28.70 with SMTP id z6mr41990obg.16.1395267241024;
        Wed, 19 Mar 2014 15:14:01 -0700 (PDT)
In-Reply-To: <lgcl91$uln$1@ger.gmane.org>
X-Original-Sender: mizvekov@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:9977
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/9977>

------=_Part_62_5262444.1395267240238
Content-Type: text/plain; charset=UTF-8

On Wednesday, March 19, 2014 2:48:31 PM UTC-3, Matthew Woehlke wrote:
>
>
> That would be awesome. In fact I have a 'to do' to suggest exactly this. 
>
> std::flags might cover that specific use case, but I also want to be 
> able to do things like: 
>
>    enum class foo { 
>      ...values... 
>      foo(std::string const*); // constructor 
>      operator std::string(); // conversion operator 
>    }; 
>
> (These sorts of conversions already show up frequently, but right now 
> must be implemented as free functions; the ability to make them members 
> would be great.) 
>
>
>  
But now that really starts to diverge from Walter's proposal.
It seems he did leave out member functions/operators on purpose.
If you want to leverage his work, it seems the best option would be to have
a non-member form of the cast operator, and also replace the constructor 
with that.
Something like:
enum class foo {
     ...values...;

     operator std::string(const foo &); // conversion to string operator
     operator foo(const std::string &); // conversion from string operator
};


Something else I would really love to see though is using an enumeration 
> as an underlying ("base") type of an enumeration, e.g.: 
>
>    enum class A { a1, a2, ... }; 
>    enum class B : A { b1, b2, ... }; 
>
>    B bb = B::a1; // legal; a1, etc. are in scope of B, inherited from A 
>
>
But would then be implicit conversions from A allowed?
B bb = A::a1;
I would suggest not, because this behavior would need to be a special case.

Also, what would be the underlying_type_t of B? Would it be A or int?

If it could be A, that could be surprising for a lot of code. It would also 
not play well with Thiago Macieira's idea of multiple inheritance.

At the same type, it would be interesting to have type_traits to query the 
hierarchy of such enums.

How to implement that then? Specialize std::is_base_of?

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_62_5262444.1395267240238
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, March 19, 2014 2:48:31 PM UTC-3, Matthew Woe=
hlke wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>
That would be awesome. In fact I have a 'to do' to suggest exactly this.
<br>
<br>std::flags might cover that specific use case, but I also want to be=20
<br>able to do things like:
<br>
<br>&nbsp; &nbsp;enum class foo {
<br>&nbsp; &nbsp; &nbsp;...values...
<br>&nbsp; &nbsp; &nbsp;foo(std::string const*); // constructor
<br>&nbsp; &nbsp; &nbsp;operator std::string(); // conversion operator
<br>&nbsp; &nbsp;};
<br>
<br>(These sorts of conversions already show up frequently, but right now=
=20
<br>must be implemented as free functions; the ability to make them members=
=20
<br>would be great.)
<br>
<br>
<br></blockquote><div>&nbsp;<br>But now that really starts to diverge from =
Walter's proposal.<br>It seems he did leave out member functions/operators =
on purpose.<br>If you want to leverage his work, it seems the best option w=
ould be to have<br>a non-member form of the cast operator, and also replace=
 the constructor with that.<br>Something like:<br><div class=3D"prettyprint=
" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187=
, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">enum</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> foo </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>&nbsp; &nbsp; &nbsp;</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">...</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">values</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">...;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=
&nbsp; &nbsp; &nbsp;</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">operator</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">::</span><span style=3D"color: #008;" class=3D"styled-by-prettify">string=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> foo </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&amp;);</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">// conversion to string operator</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"></span><br><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><code class=3D"prettypri=
nt"><span style=3D"color: #008;" class=3D"styled-by-prettify">&nbsp;&nbsp;&=
nbsp;&nbsp; operator</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> foo</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy"></span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> std::string </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;);</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// conversion from string op=
erator</span><span style=3D"color: #000;" class=3D"styled-by-prettify"></sp=
an></code><br></span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span></div></code></div><br><br></div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-le=
ft: 1ex;">Something else I would really love to see though is using an enum=
eration=20
<br>as an underlying ("base") type of an enumeration, e.g.:
<br>
<br>&nbsp; &nbsp;enum class A { a1, a2, ... };
<br>&nbsp; &nbsp;enum class B : A { b1, b2, ... };
<br>
<br>&nbsp; &nbsp;B bb =3D B::a1; // legal; a1, etc. are in scope of B, inhe=
rited from A
<br>
<br></blockquote><div><br>But would then be implicit conversions from A all=
owed?<br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250=
, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width=
: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"su=
bprettyprint"><span style=3D"color: #606;" class=3D"styled-by-prettify">B b=
b =3D A::a1;</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
"></span></div></code></div>I would suggest not, because this behavior woul=
d need to be a special case.<br><br>Also, what would be the underlying_type=
_t of B? Would it be A or int?<br><br>If it could be A, that could be surpr=
ising for a lot of code. It would also not play well with Thiago Macieira's=
 idea of multiple inheritance.<br><br>At the same type, it would be interes=
ting to have type_traits to query the hierarchy of such enums.<br><br>How t=
o implement that then? Specialize std::is_base_of?<br><br></div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_62_5262444.1395267240238--

.
