Topic: Should names used in the initializer of an


Author: "'Johannes Schaub' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Tue, 7 Feb 2017 18:22:24 +0100
Raw View
Alternatively, this can be merged with "strong typedefs", so that you
can type (warning: bikeshed)

    typedef new enum { A, B, C } X;

A new-type would depend on what it alias. Aliasing a new-type with an
enumeration type creates pretty much what currently a scoped
enumeration is, just as a "new" type without the
strongly-scoping-thing. Aliasing a new-type with a class type would be
ill-formed. Aliasing a new-type with an integer would create a new
integer type.. Aliasing an array type would apply the new-type
transformation onto the element type. Same for new-typing a pointer
type.


2017-02-07 17:44 GMT+01:00 Matthew Woehlke <mwoehlke.floss@gmail.com>:
> On 2017-02-07 01:12, Brian Bi wrote:
>> For example, should the following code be made well-formed?
>>
>> enum class Color {
>>     RED,
>>     GREEN,
>>     BLUE,
>> };
>>
>> Color color = RED;
>
> Not by itself, no. In general, *YES PLEASE*!
>
> My biggest hatred of strongly typed enums, and why I rarely use them, is
> that they conflated two orthogonal features: implicit conversion (i.e.
> that they *don't* implicitly convert), and scoping of the enumeration
> values.
>
> Fortunately, C++11 made it legal to name enumerators by their containing
> enumeration for both "classic" and "strongly typed" enumerations, which
> lessens the need for weakly-typed, strongly-scoped enumerations.
> However, there is as yet no good solution for strongly-typed,
> weakly-scoped enumerations, despite a fairly common desire for such
> critters.
>
> I'd like to see something like `using enum Color` to make the
> enumerators of a named enumeration available in a different scope.
>
> Note that this would not be *just* the parent scope. For example:
>
>   namespace zoo {
>     enum class Animal { Dog, Cat, Cow, Pig };
>   }
>   namespace farm { using enum ::zoo::Animal; }
>
>   auto x = farm::Dog; // okay; decltype(x) == ::zoo::Animal
>
> --
> Matthew
>
> --
> 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/5899F95E.8060407%40gmail.com.

--
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/CANu6V4VcppVPV_SimT%2BwGTL9Cp%3DDxHRpQJvsECoRgy0fBYySrQ%40mail.gmail.com.

.


Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 26 Feb 2019 14:44:30 +0000
Raw View
--000000000000ed10bd0582cd1890
Content-Type: text/plain; charset="UTF-8"

That's not how lookup works :). You need to figure out what type your
arguments are *before* you resolve the call.

However, as a partial fix to your predicament, my paper "Using Enum" made
it to C++20.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r3.html

On Tue, Feb 26, 2019 at 2:17 PM <mobile.schewe@gmail.com> wrote:

> I use enums quite a bit in my code as it is nice to have strongly typed
> values used for passing to functions and switching.
>
> I'd like to propose the following as the name of such code:
> Argument Dependent Name Lookup for Strongly Typed Enums
>
> ADNL is already used for variables and methods within the current scope
> such as inside the same class or namespace,
> but enums are still a case where the scope strongly suggests that the
> value should be a member of an enum, yet must still be fully qualified.
>
> Let me give a few examples:
>
> enum class SpacialUnit {
>     Inch,
>     Millimeter,
>     Point,
>     Pixel,
> };
>
>
> // assignment to a variable cannot be anything other than the type of the
> variable
> SpacialUnit unit = Inch;
>
>
> // passing to a function that requires that type
> Translate(10, Inch);
> // where Translate is declared:
> void Translate(int, SpacialUnit);
>
>
> // returning from a function that declares that type
> SpacialUnit GetUnit() {
>     return Inch;
> }
>
>
> // switching on a variable of that type
> SpacialUnit unit;
> switch (unit) {
>     case Inch: break;
>     case Millimeter: break;
> }
>
>
> // passing as a constexpr value to a template that declares argument type
> template <SpacialUnit unit>
> class Rectangle {
>     ...
> };
>
> Rectangle<Inch> saeRect;
>
>
> In every single one of those cases mentioned above, there is no other
> possible value besides a member of the enum that can be accepted without
> explicit casting.
> So why should we be required to qualify the enum name in these cases?
>
> --
> 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/f2442186-7637-487d-ba01-919b6ef9f3e7%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2442186-7637-487d-ba01-919b6ef9f3e7%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

--
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/CAANG%3DkXAZbiVoBQMQZd2g1nbVnk%2BFnYMetjrNcEwpS3Pph4SBQ%40mail.gmail.com.

--000000000000ed10bd0582cd1890
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">That&#39;s not how lookup works :). You n=
eed to figure out what type your arguments are *before* you resolve the cal=
l.<div><br></div><div>However, as a partial fix to your predicament, my pap=
er &quot;Using Enum&quot; made it to C++20. <a href=3D"http://www.open-std.=
org/jtc1/sc22/wg21/docs/papers/2019/p1099r3.html">http://www.open-std.org/j=
tc1/sc22/wg21/docs/papers/2019/p1099r3.html</a></div></div></div><br><div c=
lass=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Feb 26, =
2019 at 2:17 PM &lt;<a href=3D"mailto:mobile.schewe@gmail.com">mobile.schew=
e@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex"><div dir=3D"ltr">I use enums quite a bit in my code as it is nic=
e to have strongly typed values used for passing to functions and switching=
..<div><br></div><div>I&#39;d like to propose the following as the name of s=
uch code:</div><div>Argument Dependent Name Lookup for Strongly Typed Enums=
<br></div><div><br></div><div>ADNL is already used for variables and method=
s within the current scope such as inside the same class or namespace,</div=
><div>but enums are still a case where the scope strongly suggests that the=
 value should be a member of an enum, yet must still be fully qualified.</d=
iv><div><br></div><div>Let me give a few examples:</div><div><br></div><div=
><div class=3D"gmail-m_-6659342346752754237prettyprint" style=3D"background=
-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;bo=
rder-width:1px"><code class=3D"gmail-m_-6659342346752754237prettyprint"><di=
v class=3D"gmail-m_-6659342346752754237subprettyprint"><span style=3D"color=
:rgb(0,0,136)" class=3D"gmail-m_-6659342346752754237styled-by-prettify">enu=
m</span><span style=3D"color:rgb(0,0,0)" class=3D"gmail-m_-6659342346752754=
237styled-by-prettify"> </span><span style=3D"color:rgb(0,0,136)" class=3D"=
gmail-m_-6659342346752754237styled-by-prettify">class</span><span style=3D"=
color:rgb(0,0,0)" class=3D"gmail-m_-6659342346752754237styled-by-prettify">=
 </span><span style=3D"color:rgb(102,0,102)" class=3D"gmail-m_-665934234675=
2754237styled-by-prettify">SpacialUnit</span><span style=3D"color:rgb(0,0,0=
)" class=3D"gmail-m_-6659342346752754237styled-by-prettify">=C2=A0</span><s=
pan style=3D"color:rgb(102,102,0)" class=3D"gmail-m_-6659342346752754237sty=
led-by-prettify">{</span><span style=3D"color:rgb(0,0,0)" class=3D"gmail-m_=
-6659342346752754237styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span styl=
e=3D"color:rgb(102,0,102)" class=3D"gmail-m_-6659342346752754237styled-by-p=
rettify">Inch</span><span style=3D"color:rgb(102,102,0)" class=3D"gmail-m_-=
6659342346752754237styled-by-prettify">,</span><span style=3D"color:rgb(0,0=
,0)" class=3D"gmail-m_-6659342346752754237styled-by-prettify"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:rgb(102,0,102)" class=3D"gmail-m_-665934=
2346752754237styled-by-prettify">Millimeter</span><span style=3D"color:rgb(=
102,102,0)" class=3D"gmail-m_-6659342346752754237styled-by-prettify">,</spa=
n></div><div class=3D"gmail-m_-6659342346752754237subprettyprint"><span cla=
ss=3D"gmail-m_-6659342346752754237styled-by-prettify"><font color=3D"#66660=
0">=C2=A0 =C2=A0 Point,<br>=C2=A0 =C2=A0 Pixel,<br></font></span><span styl=
e=3D"color:rgb(102,102,0)" class=3D"gmail-m_-6659342346752754237styled-by-p=
rettify">};<br><br><br>// assignment to a variable cannot be anything other=
 than the type of the variable<br>SpacialUnit unit =3D Inch;<br><br><br>// =
passing to a function that requires that type<br>Translate(10, Inch);<br>//=
 where Translate is declared:<br>void Translate(int, SpacialUnit);<br><br><=
br>// returning from a function that declares that type<br>SpacialUnit GetU=
nit() {<br>=C2=A0 =C2=A0 return Inch;<br>}<br><br><br>// switching on a var=
iable of that type<br>SpacialUnit unit;<br>switch (unit) {<br>=C2=A0 =C2=A0=
 case Inch: break;<br>=C2=A0 =C2=A0 case Millimeter: break;<br>}<br><br><br=
>// passing as a constexpr value to a template that declares argument type<=
br>template &lt;SpacialUnit unit&gt;<br>class Rectangle {<br>=C2=A0 =C2=A0 =
....<br>};<br><br>Rectangle&lt;Inch&gt; saeRect;<br><br></span></div></code>=
</div><br>In every single one of those cases mentioned above, there is no o=
ther possible value besides a member of the enum that can be accepted witho=
ut explicit casting.</div><div>So why should we be required to qualify the =
enum name in these cases?</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" 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/f2442186-7637-487d-ba01-919b6ef9f3e7%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2442186-7637-=
487d-ba01-919b6ef9f3e7%40isocpp.org</a>.<br>
</blockquote></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/CAANG%3DkXAZbiVoBQMQZd2g1nbVnk%2BFnYM=
etjrNcEwpS3Pph4SBQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkXAZb=
iVoBQMQZd2g1nbVnk%2BFnYMetjrNcEwpS3Pph4SBQ%40mail.gmail.com</a>.<br />

--000000000000ed10bd0582cd1890--

.