Topic: Type-traits idea: enumerators_per_value, and two more
Author: Daryle Walker <darylew@gmail.com>
Date: Thu, 3 Oct 2013 02:33:54 -0700 (PDT)
Raw View
------=_Part_5954_22245589.1380792834234
Content-Type: text/plain; charset=ISO-8859-1
While thinking about another problem, I remember reading posts here about
messing with enumerator values. I thought that there should be a way to
check if a particular value was being used in an enum:
template < typename EnumType, underlying_type_t<EnumType> Value >
struct is_enumerator_value
: integral_constant< bool, COMPILER_MAGIC >
{ };
So if a value isn't being used for any of the enumerators for a type, the
class value is false, while true for any other value. Then I realized that
the mapping given is the reverse of integer-to-Boolean casts, so why don't
I make it a full count instead. The class value can still work correctly
for Boolean contexts. My first name for the new trait was
"count_enumerator_value," which changed to "enumerators_per_value." But I
think a better name is possible:
template < typename EnumType, underlying_type_t<EnumType> Value >
struct enumerators
: integral_constant< size_t, COMPILER_MAGIC >
{ };
The name would be used as the same part of speech like the "rank" and
"extent" type trait class templates are. Any better suggestions? (I just
thought of "has_enumerators," but the name implies strict-Boolean instead
of Boolean-compatible.)
Now if we could have another type traits that mirrors an array (or
std::array) of values that cover all the ones that have an enumerator:
template < typename EnumType >
struct enumerator_values
: integral_constant< array<underlying_type_t<EnumType>,
COMPILER_MAGIC>, COMPILER_MAGIC >
{ };
But we may have to settle for "enumerator_unique_value_count" and
"enumerator_unique_value." (The latter takes the enumeration type and an
index. The indexes range from 0 to enumerator_unique_value_count<EnumType>::value
- 1.) Note there is no function returning an enumerator given an
integer value. It couldn't work anyway since the mapping can
be one-to-many.
Daryle W.
--
---
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_5954_22245589.1380792834234
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>While thinking about another problem, I remember read=
ing posts here about messing with enumerator values. I thought that t=
here should be a way to check if a particular value was being used in an en=
um:</div><div> </div><blockquote style=3D"margin-right: 0px;" dir=3D"l=
tr"><div><font face=3D"courier new,monospace">template < typename EnumTy=
pe, underlying_type_t<EnumType> Value ></font></div><div><font fac=
e=3D"courier new,monospace">struct is_enumerator_value</font></div><div><fo=
nt face=3D"courier new,monospace"> : integral_constant<=
; bool, COMPILER_MAGIC ></font></div><div><font face=3D"courier new,mono=
space">{ };</font></div></blockquote><div> </div><div>So if a value is=
n't being used for any of the enumerators for a type, the class value is fa=
lse, while true for any other value. Then I realized that the mapping=
given is the reverse of integer-to-Boolean casts, so why don't I make it a=
full count instead. The class value can still work correctly for Boo=
lean contexts. My first name for the new trait was "count_enumerator_=
value," which changed to "enumerators_per_value." But I think a bette=
r name is possible:</div><div> </div><blockquote style=3D"margin-right=
: 0px;" dir=3D"ltr"><div><font face=3D"courier new,monospace">template <=
typename EnumType, underlying_type_t<EnumType> Value ></font></di=
v><div><font face=3D"courier new,monospace">struct enumerators</font></div>=
<div><font face=3D"courier new,monospace"> : integral_con=
stant< size_t, COMPILER_MAGIC ></font></div><div><font face=3D"courie=
r new,monospace">{ };</font></div></blockquote><div> </div><div>The na=
me would be used as the same part of speech like the "rank" and "extent" ty=
pe trait class templates are. Any better suggestions? (I just t=
hought of "has_enumerators," but the name implies strict-Boolean instead of=
Boolean-compatible.)</div><div> </div><div>Now if we could have anoth=
er type traits that mirrors an array (or std::array) of values that cover a=
ll the ones that have an enumerator:</div><div> </div><blockquote styl=
e=3D"margin-right: 0px;" dir=3D"ltr"><div><font face=3D"courier new,monospa=
ce">template < typename EnumType ></font></div><div><font face=3D"cou=
rier new,monospace">struct enumerator_values</font></div><div><font face=3D=
"courier new,monospace"> : integral_constant< array<=
;underlying_type_t<EnumType>, COMPILER_MAGIC>, COMPILER_MAGIC >=
</font></div><div><font face=3D"courier new,monospace">{ };</font></div></b=
lockquote><div> </div><div>But we may have to settle for "enumerator_u=
nique_value_count" and "enumerator_unique_value." (The latter takes t=
he enumeration type and an index. The indexes range from 0 to <font f=
ace=3D"courier new,monospace">enumerator_unique_value_count<EnumType>=
::value - 1</font>.) Note there is no function returning an enum=
erator given an integer value. It couldn't work anyway since the=
mapping can be one-to-many.</div><div> </div><div>Daryle W.=
</div><div> </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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_5954_22245589.1380792834234--
.
Author: Maurice Bos <m-ou.se@m-ou.se>
Date: Thu, 3 Oct 2013 11:48:37 +0200
Raw View
--001a11c2409e3db7bf04e7d3185a
Content-Type: text/plain; charset=ISO-8859-1
Sounds like something for the reflection mailing list (reflection@isocpp.org
).
2013/10/3 Daryle Walker <darylew@gmail.com>
> While thinking about another problem, I remember reading posts here about
> messing with enumerator values. I thought that there should be a way to
> check if a particular value was being used in an enum:
>
>
> template < typename EnumType, underlying_type_t<EnumType> Value >
> struct is_enumerator_value
> : integral_constant< bool, COMPILER_MAGIC >
> { };
>
>
> So if a value isn't being used for any of the enumerators for a type, the
> class value is false, while true for any other value. Then I realized that
> the mapping given is the reverse of integer-to-Boolean casts, so why don't
> I make it a full count instead. The class value can still work correctly
> for Boolean contexts. My first name for the new trait was
> "count_enumerator_value," which changed to "enumerators_per_value." But I
> think a better name is possible:
>
>
> template < typename EnumType, underlying_type_t<EnumType> Value >
> struct enumerators
> : integral_constant< size_t, COMPILER_MAGIC >
> { };
>
>
> The name would be used as the same part of speech like the "rank" and
> "extent" type trait class templates are. Any better suggestions? (I just
> thought of "has_enumerators," but the name implies strict-Boolean instead
> of Boolean-compatible.)
>
> Now if we could have another type traits that mirrors an array (or
> std::array) of values that cover all the ones that have an enumerator:
>
>
> template < typename EnumType >
> struct enumerator_values
> : integral_constant< array<underlying_type_t<EnumType>,
> COMPILER_MAGIC>, COMPILER_MAGIC >
> { };
>
>
> But we may have to settle for "enumerator_unique_value_count" and
> "enumerator_unique_value." (The latter takes the enumeration type and an
> index. The indexes range from 0 to enumerator_unique_value_count<EnumType>::value
> - 1.) Note there is no function returning an enumerator given an
> integer value. It couldn't work anyway since the mapping can
> be one-to-many.
>
> Daryle W.
>
>
> --
>
> ---
> 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/.
>
--
---
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/.
--001a11c2409e3db7bf04e7d3185a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Sounds like something for the reflection mailing list (<sp=
an class=3D""><span><a href=3D"mailto:reflection@isocpp.org">reflection@iso=
cpp.org</a>).</span></span></div><div class=3D"gmail_extra"><br><br><div cl=
ass=3D"gmail_quote">
2013/10/3 Daryle Walker <span dir=3D"ltr"><<a href=3D"mailto:darylew@gma=
il.com" target=3D"_blank">darylew@gmail.com</a>></span><br><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;=
padding-left:1ex">
<div dir=3D"ltr"><div>While thinking about another problem, I remember read=
ing posts here about messing with enumerator values.=A0 I thought that ther=
e should be a way to check if a particular value was being used in an enum:=
</div>
<div>=A0</div><blockquote style=3D"margin-right:0px" dir=3D"ltr"><div><font=
face=3D"courier new,monospace">template < typename EnumType, underlying=
_type_t<EnumType> Value ></font></div><div><font face=3D"courier n=
ew,monospace">struct is_enumerator_value</font></div>
<div><font face=3D"courier new,monospace">=A0=A0=A0 : integral_constant<=
bool, COMPILER_MAGIC ></font></div><div><font face=3D"courier new,monos=
pace">{ };</font></div></blockquote><div>=A0</div><div>So if a value isn=
9;t being used for any of the enumerators for a type, the class value is fa=
lse, while true for any other value.=A0 Then I realized that the mapping gi=
ven is the reverse of integer-to-Boolean casts, so why don't I make it =
a full count instead.=A0 The class value can still work correctly for Boole=
an contexts.=A0 My first name for the new trait was "count_enumerator_=
value," which changed to "enumerators_per_value."=A0 But I t=
hink a better name is possible:</div>
<div>=A0</div><blockquote style=3D"margin-right:0px" dir=3D"ltr"><div><font=
face=3D"courier new,monospace">template < typename EnumType, underlying=
_type_t<EnumType> Value ></font></div><div><font face=3D"courier n=
ew,monospace">struct enumerators</font></div>
<div><font face=3D"courier new,monospace">=A0=A0=A0 : integral_constant<=
size_t, COMPILER_MAGIC ></font></div><div><font face=3D"courier new,mon=
ospace">{ };</font></div></blockquote><div>=A0</div><div>The name would be =
used as the same part of speech like the "rank" and "extent&=
quot; type trait class templates are.=A0 Any better suggestions?=A0 (I just=
thought of "has_enumerators," but the name implies strict-Boolea=
n instead of Boolean-compatible.)</div>
<div>=A0</div><div>Now if we could have another type traits that mirrors an=
array (or std::array) of values that cover all the ones that have an enume=
rator:</div><div>=A0</div><blockquote style=3D"margin-right:0px" dir=3D"ltr=
"><div>
<font face=3D"courier new,monospace">template < typename EnumType ></=
font></div><div><font face=3D"courier new,monospace">struct enumerator_valu=
es</font></div><div><font face=3D"courier new,monospace">=A0=A0=A0 : integr=
al_constant< array<underlying_type_t<EnumType>, COMPILER_MAGIC&=
gt;, COMPILER_MAGIC ></font></div>
<div><font face=3D"courier new,monospace">{ };</font></div></blockquote><di=
v>=A0</div><div>But we may have to settle for "enumerator_unique_value=
_count" and "enumerator_unique_value."=A0 (The latter takes =
the enumeration type and an index.=A0 The indexes range from 0 to <font fac=
e=3D"courier new,monospace">enumerator_unique_value_count<EnumType>::=
value - 1</font>.)=A0 Note=A0there is no function returning an enumerator g=
iven an integer=A0value.=A0 It couldn't work anyway since the mapping=
=A0can be=A0one-to-many.</div>
<div>=A0</div><div>Daryle W.</div><span class=3D"HOEnZb"><font color=3D"#88=
8888"><div>=A0</div></font></span></div><span class=3D"HOEnZb"><font color=
=3D"#888888">
<p></p>
-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@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>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
--001a11c2409e3db7bf04e7d3185a--
.