Topic: Enumerator Traits, rev 2
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Tue, 1 Oct 2013 01:52:43 -0700 (PDT)
Raw View
------=_Part_2608_17940293.1380617563287
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
In order to allow library authors to build various helper utilities and=20
checkers for enumeration types during translation, we propose adding three=
=20
constexpr template functions to the Metaprogramming and Type Traits [meta]=
=20
standard library that allow the enumerators of an enumeration type be=20
iterated, and for the value and identifier of each enumerator to be=20
inspected (all during translation).
namespace std
{
template<class E> constexpr size_t enumeration_size();
template<class E, size_t i> constexpr E enumerator_value();
template<class E, size_t i> constexpr const char*=20
enumerator_identifier();
};
For all three functions, if a program calls for an instantiation where E is=
=20
not an enumeration type, or an i is not less than the number of enumerators=
=20
in E, the program is ill-formed; no diagnostic required.
enumeration_size<E>() shall return the number of enumerators in E.
enumerator_value<E,i>() shall return the value of the (zero-based) ith=20
enumerator of E in declared order.
enumerator_identifier<E,i>() shall return a pointer to an element of an=20
array, such that it starts a UTF-8 encoded null-terminated string of the=20
identifier of the (zero-based) ith enumerator of E in declared order. =20
universal-character-names in the identifier are decoded. The array shall=
=20
be such that an lvalue-to-rvalue conversion is permitted on the elements of=
=20
the array within a core constant expression. [Note: This would be the case=
=20
if the array is a string literal or is defined with constexpr: -end note]
Example:
enum Efoo
{
bar =3D 42,
baz =3D 43,
qux =3D 44,
e=CF=80 =3D 42,
f\u03C0 =3D 42,
};
As if the implementation provides the following specializations:
template<> constexpr size_t enumeration_size<Efoo>() { return 5; }
template<> constexpr Efoo enumerator_value<Efoo,0>() { return bar; }
template<> constexpr Efoo enumerator_value<Efoo,1>() { return baz; }
template<> constexpr Efoo enumerator_value<Efoo,2>() { return qux; }
template<> constexpr Efoo enumerator_value<Efoo,3>() { return e=CF=80; =
}
template<> constexpr Efoo enumerator_value<Efoo,4>() { return f\u03C0; =
}
template<> constexpr Efoo enumerator_identifier<Efoo,0>() { return u8"
bar"; }
template<> constexpr Efoo enumerator_identifier<Efoo,1>() { return u8"
baz"; }
template<> constexpr Efoo enumerator_identifier<Efoo,2>() { return u8"
qux"; }
template<> constexpr Efoo enumerator_identifier<Efoo,3>() { return u8"e=
=CF=80";=20
}
template<> constexpr Efoo enumerator_identifier<Efoo,4>() { return u8"
f\u03C0"; }
Using a std::integer_sequence it is possible to form an initializer list=20
such as:
std::multimap<Efoo, const char*> value_to_identifier =3D { {=20
enumerator_value<Efoo, i>(), enumerator_identifier<Efoo, i>() }... };
or
std::map<std::string, Efoo> identifier_to_value =3D { { enumerator_
identifier<Efoo, i>(), enumerator_value<Efoo, i>() }... };
Because the elements of the identifier string can be inspected in a=20
constant expression, and because UTF-8 encodes all universal characters, it=
=20
is possible to transcode the identifier strings to any encoding during=20
translation, as well as applying whatever static checks on the enumerator=
=20
values or identifiers that one may want to apply.
Using std::integer_sequence it is also possible to form a pack consisting=
=20
of the enumerators in declared order:
template<Efoo... enumerator_pack>
void f();
f<enumerator_value<Efoo,i>()...>();
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_2608_17940293.1380617563287
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><span style=3D"font-family: courier new,monospace;"><span =
style=3D"font-family: arial,sans-serif;">In order to allow library authors =
to build various helper utilities and checkers for enumeration types during=
translation, we propose adding three constexpr template functions to the M=
etaprogramming and Type Traits [meta] standard library that allow the enume=
rators of an enumeration type be iterated, and for the value and identifier=
of each enumerator to be inspected (all during translation).<br></span><br=
>namespace std<br>{<br> template&=
lt;class E> constexpr size_t enumeration_size();<br> &n=
bsp; template<class E, size_t i> constexpr E enumer=
ator_value();<br> template<cla=
ss E, size_t i> constexpr const char* enumerator_identifier();<br>};<br>=
</span><br>For all three functions, if a program calls for an instantiation=
where <span style=3D"font-family: courier new,monospace;">E</span> is not =
an enumeration type, or an<span style=3D"font-family: courier new,monospace=
;"> i</span> is not less than the number of enumerators in <span style=3D"f=
ont-family: courier new,monospace;">E</span>, the program is ill-formed; no=
diagnostic required.<br><br><span style=3D"font-family: courier new,monosp=
ace;">enumeration_size<E>()</span> shall return the number of enumera=
tors in <span style=3D"font-family: courier new,monospace;">E</span>.<br><b=
r><span style=3D"font-family: courier new,monospace;">enumerator_value<E=
,i>()</span> shall return the value of the (zero-based) <span style=3D"f=
ont-family: courier new,monospace;">i</span>th enumerator of <span style=3D=
"font-family: courier new,monospace;">E</span> in declared order.<br><span =
style=3D"font-family: courier new,monospace;"><br>enumerator_identifier<=
E,i>()</span> shall return a pointer to an element of an array, such tha=
t it starts a UTF-8 encoded null-terminated string of the identifier of the=
(zero-based) ith enumerator of E in declared order. universal-charac=
ter-names in the identifier are decoded. The array shall be such that=
an lvalue-to-rvalue conversion is permitted on the elements of the array w=
ithin a core constant expression. [Note: This would be the case if the arra=
y is a string literal or is defined with constexpr: -end note]<br><br>Examp=
le:<br><br><span style=3D"font-family:courier new,monospace"> &n=
bsp; enum Efoo<br> {<br> &nb=
sp; bar =3D 42,<br> baz =3D=
43,<br> qux =3D 44,<br> &nb=
sp; e=CF=80 =3D 42,<br> &nbs=
p; f\u03C0 =3D 42,<br> };<br><br>As if =
the implementation provides the following specializations:<br><br> &nb=
sp; template<> constexpr size_t enumeration_size<Efoo>() =
{ return 5; }<br><br></span><span style=3D"font-family:courier new,monospac=
e"> template<> constexpr Efoo enumerator_value<E=
foo,0>() { return bar; }</span><br><span style=3D"font-family:courier ne=
w,monospace"> template<> constexpr Efoo enumerator_=
value<Efoo,1>() { return </span><span style=3D"font-family:courier ne=
w,monospace"><span style=3D"font-family:courier new,monospace">baz</span>; =
}</span><br><span style=3D"font-family:courier new,monospace"> &=
nbsp; template<> constexpr Efoo enumerator_value<Efoo,2>() { re=
turn </span><span style=3D"font-family:courier new,monospace"><span style=
=3D"font-family:courier new,monospace">qux</span>; }</span><br><span style=
=3D"font-family:courier new,monospace"> template<> =
constexpr Efoo enumerator_value<Efoo,3>() { return </span><span style=
=3D"font-family:courier new,monospace"><span style=3D"font-family:courier n=
ew,monospace">e=CF=80</span>; }</span><br><span style=3D"font-family:courie=
r new,monospace"> template<> constexpr Efoo enumera=
tor_value<Efoo,4>() { return </span><span style=3D"font-family:courie=
r new,monospace"><span style=3D"font-family:courier new,monospace">f\u03C0<=
/span>; }<br><br></span><span style=3D"font-family:courier new,monospace">&=
nbsp; template<> constexpr Efoo enumerator_identifier<=
Efoo,0>() { return u8"</span><span style=3D"font-family:courier new,mono=
space"><span style=3D"font-family:courier new,monospace">bar</span>"; }<br>=
</span><span style=3D"font-family:courier new,monospace"> =
template<> constexpr Efoo enumerator_</span><span style=3D"font-fami=
ly:courier new,monospace"><span style=3D"font-family:courier new,monospace"=
>identifier</span><Efoo,1>() { return u8"</span><span style=3D"font-f=
amily:courier new,monospace">baz</span><span style=3D"font-family:courier n=
ew,monospace">"; }<br></span><span style=3D"font-family:courier new,monospa=
ce"> template<> constexpr Efoo enumerator_</span><s=
pan style=3D"font-family:courier new,monospace"><span style=3D"font-family:=
courier new,monospace">identifier</span><Efoo,2>() { return u8"</span=
><span style=3D"font-family:courier new,monospace">qux</span><span style=3D=
"font-family:courier new,monospace">"; }<br></span><span style=3D"font-fami=
ly:courier new,monospace"> template<> constexpr Efo=
o enumerator_</span><span style=3D"font-family:courier new,monospace"><span=
style=3D"font-family:courier new,monospace">identifier</span><Efoo,3>=
;() { return u8"</span><span style=3D"font-family:courier new,monospace">e=
=CF=80</span><span style=3D"font-family:courier new,monospace">"; }<br></sp=
an><span style=3D"font-family:courier new,monospace"> tem=
plate<> constexpr Efoo enumerator_</span><span style=3D"font-family:c=
ourier new,monospace"><span style=3D"font-family:courier new,monospace">ide=
ntifier</span><Efoo,4>() { return u8"</span><span style=3D"font-famil=
y:courier new,monospace">f\u03C0</span><span style=3D"font-family:courier n=
ew,monospace">"; }<br></span><span style=3D"font-family:courier new,monospa=
ce"><br>Using a std::integer_sequence it is possible to form an initializer=
list such as:<br><br> std::multimap<Efoo, const char*=
> value_to_identifier =3D { { enumerator_value<Efoo, i>(), enumera=
tor_</span><span style=3D"font-family:courier new,monospace"><span style=3D=
"font-family:courier new,monospace">identifier</span><Efoo, i>() }...=
};<br><br>or<br><br> std::map<std::string, Efoo> i=
dentifier_to_value =3D { { enumerator_</span><span style=3D"font-family:cou=
rier new,monospace"><span style=3D"font-family:courier new,monospace">ident=
ifier</span><Efoo, i>(), enumerator_value<Efoo, i>() }... };<br=
><span style=3D"font-family: arial,sans-serif;"><br>Because the elements of=
the identifier string can be inspected in a constant expression, and becau=
se UTF-8 encodes all universal characters, it is possible to transcode the =
identifier strings to any encoding during translation, as well as applying =
whatever static checks on the enumerator values or identifiers that one may=
want to apply.<br><br>Using <span style=3D"font-family: courier new,monosp=
ace;">std::integer_sequence</span> it is also possible to form a pack consi=
sting of the enumerators in declared order:<br><br><span style=3D"font-fami=
ly: courier new,monospace;"> template<Efoo... en=
umerator_pack><br> void f();<br><br> =
f<enumerator_value<Efoo,i>()...>();<br></span></sp=
an><br></span><span style=3D"font-family:courier new,monospace"></span></di=
v>
<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_2608_17940293.1380617563287--
.
Author: Maurice Bos <m-ou.se@m-ou.se>
Date: Tue, 1 Oct 2013 12:08:56 +0200
Raw View
--e89a8f2355c73b276804e7ab25d7
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Why functions? Starting in C++14 we have variable templates, right?
2013/10/1 Andrew Tomazos <andrewtomazos@gmail.com>
> In order to allow library authors to build various helper utilities and
> checkers for enumeration types during translation, we propose adding thre=
e
> constexpr template functions to the Metaprogramming and Type Traits [meta=
]
> standard library that allow the enumerators of an enumeration type be
> iterated, and for the value and identifier of each enumerator to be
> inspected (all during translation).
>
> namespace std
> {
> template<class E> constexpr size_t enumeration_size();
> template<class E, size_t i> constexpr E enumerator_value();
> template<class E, size_t i> constexpr const char*
> enumerator_identifier();
> };
>
> For all three functions, if a program calls for an instantiation where Ei=
s not an enumeration type, or aniis not less than the number of enumerators=
in
> E, the program is ill-formed; no diagnostic required.
>
> enumeration_size<E>() shall return the number of enumerators in E.
>
> enumerator_value<E,i>() shall return the value of the (zero-based) ith
> enumerator of E in declared order.
>
> enumerator_identifier<E,i>() shall return a pointer to an element of an
> array, such that it starts a UTF-8 encoded null-terminated string of the
> identifier of the (zero-based) ith enumerator of E in declared order.
> universal-character-names in the identifier are decoded. The array shall
> be such that an lvalue-to-rvalue conversion is permitted on the elements =
of
> the array within a core constant expression. [Note: This would be the cas=
e
> if the array is a string literal or is defined with constexpr: -end note]
>
> Example:
>
> enum Efoo
> {
> bar =3D 42,
> baz =3D 43,
> qux =3D 44,
> e=CF=80 =3D 42,
> f\u03C0 =3D 42,
> };
>
> As if the implementation provides the following specializations:
>
> template<> constexpr size_t enumeration_size<Efoo>() { return 5; }
>
> template<> constexpr Efoo enumerator_value<Efoo,0>() { return bar; }
> template<> constexpr Efoo enumerator_value<Efoo,1>() { return baz; }
> template<> constexpr Efoo enumerator_value<Efoo,2>() { return qux; }
> template<> constexpr Efoo enumerator_value<Efoo,3>() { return e=CF=80=
; }
> template<> constexpr Efoo enumerator_value<Efoo,4>() { return f\u03C0=
;
> }
>
> template<> constexpr Efoo enumerator_identifier<Efoo,0>() { return u8=
"
> bar"; }
> template<> constexpr Efoo enumerator_identifier<Efoo,1>() { return u8=
"
> baz"; }
> template<> constexpr Efoo enumerator_identifier<Efoo,2>() { return u8=
"
> qux"; }
> template<> constexpr Efoo enumerator_identifier<Efoo,3>() { return u8=
"
> e=CF=80"; }
> template<> constexpr Efoo enumerator_identifier<Efoo,4>() { return u8=
"
> f\u03C0"; }
>
> Using a std::integer_sequence it is possible to form an initializer list
> such as:
>
> std::multimap<Efoo, const char*> value_to_identifier =3D { {
> enumerator_value<Efoo, i>(), enumerator_identifier<Efoo, i>() }... };
>
> or
>
> std::map<std::string, Efoo> identifier_to_value =3D { { enumerator_
> identifier<Efoo, i>(), enumerator_value<Efoo, i>() }... };
>
> Because the elements of the identifier string can be inspected in a
> constant expression, and because UTF-8 encodes all universal characters, =
it
> is possible to transcode the identifier strings to any encoding during
> translation, as well as applying whatever static checks on the enumerator
> values or identifiers that one may want to apply.
>
> Using std::integer_sequence it is also possible to form a pack consisting
> of the enumerators in declared order:
>
> template<Efoo... enumerator_pack>
> void f();
>
> f<enumerator_value<Efoo,i>()...>();
>
> --
>
> ---
> 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/.
>
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--e89a8f2355c73b276804e7ab25d7
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Why functions? Starting in C++14 we have variable template=
s, right?<br></div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_q=
uote">2013/10/1 Andrew Tomazos <span dir=3D"ltr"><<a href=3D"mailto:andr=
ewtomazos@gmail.com" target=3D"_blank">andrewtomazos@gmail.com</a>></spa=
n><br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><span style=3D"font-family:=
courier new,monospace"><span style=3D"font-family:arial,sans-serif">In orde=
r to allow library authors to build various helper utilities and checkers f=
or enumeration types during translation, we propose adding three constexpr =
template functions to the Metaprogramming and Type Traits [meta] standard l=
ibrary that allow the enumerators of an enumeration type be iterated, and f=
or the value and identifier of each enumerator to be inspected (all during =
translation).<br>
</span><br>namespace std<br>{<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
template<class E> constexpr size_t enumeration_size();<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 template<class E, size_t i> constex=
pr E enumerator_value();<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 temp=
late<class E, size_t i> constexpr const char* enumerator_identifier()=
;<br>
};<br></span><br>For all three functions, if a program calls for an instant=
iation where <span style=3D"font-family:courier new,monospace">E</span> is =
not an enumeration type, or an<span style=3D"font-family:courier new,monosp=
ace"> i</span> is not less than the number of enumerators in <span style=3D=
"font-family:courier new,monospace">E</span>, the program is ill-formed; no=
diagnostic required.<br>
<br><span style=3D"font-family:courier new,monospace">enumeration_size<E=
>()</span> shall return the number of enumerators in <span style=3D"font=
-family:courier new,monospace">E</span>.<br><br><span style=3D"font-family:=
courier new,monospace">enumerator_value<E,i>()</span> shall return th=
e value of the (zero-based) <span style=3D"font-family:courier new,monospac=
e">i</span>th enumerator of <span style=3D"font-family:courier new,monospac=
e">E</span> in declared order.<br>
<span style=3D"font-family:courier new,monospace"><br>enumerator_identifier=
<E,i>()</span> shall return a pointer to an element of an array, such=
that it starts a UTF-8 encoded null-terminated string of the identifier of=
the (zero-based) ith enumerator of E in declared order.=C2=A0 universal-ch=
aracter-names in the identifier are decoded.=C2=A0 The array shall be such =
that an lvalue-to-rvalue conversion is permitted on the elements of the arr=
ay within a core constant expression. [Note: This would be the case if the =
array is a string literal or is defined with constexpr: -end note]<br>
<br>Example:<br><br><span style=3D"font-family:courier new,monospace">=C2=
=A0=C2=A0=C2=A0 enum Efoo<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 bar =3D 42,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 baz =3D 43,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 qux =3D 44=
,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 e=CF=80 =3D 42,<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 f\u03C0 =3D 42,<br>=C2=A0=C2=A0=C2=A0 =
};<br><br>As if the implementation provides the following specializations:<=
br>
<br>=C2=A0=C2=A0=C2=A0 template<> constexpr size_t enumeration_size&l=
t;Efoo>() { return 5; }<br><br></span><span style=3D"font-family:courier=
new,monospace">=C2=A0=C2=A0=C2=A0 template<> constexpr Efoo enumerat=
or_value<Efoo,0>() { return bar; }</span><br>
<span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=C2=A0 templa=
te<> constexpr Efoo enumerator_value<Efoo,1>() { return </span>=
<span style=3D"font-family:courier new,monospace"><span style=3D"font-famil=
y:courier new,monospace">baz</span>; }</span><br>
<span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=C2=A0 templa=
te<> constexpr Efoo enumerator_value<Efoo,2>() { return </span>=
<span style=3D"font-family:courier new,monospace"><span style=3D"font-famil=
y:courier new,monospace">qux</span>; }</span><br>
<span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=C2=A0 templa=
te<> constexpr Efoo enumerator_value<Efoo,3>() { return </span>=
<span style=3D"font-family:courier new,monospace"><span style=3D"font-famil=
y:courier new,monospace">e=CF=80</span>; }</span><br>
<span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=C2=A0 templa=
te<> constexpr Efoo enumerator_value<Efoo,4>() { return </span>=
<span style=3D"font-family:courier new,monospace"><span style=3D"font-famil=
y:courier new,monospace">f\u03C0</span>; }<br>
<br></span><span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=
=C2=A0 template<> constexpr Efoo enumerator_identifier<Efoo,0>(=
) { return u8"</span><span style=3D"font-family:courier new,monospace"=
><span style=3D"font-family:courier new,monospace">bar</span>"; }<br>
</span><span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=C2=A0=
template<> constexpr Efoo enumerator_</span><span style=3D"font-fami=
ly:courier new,monospace"><span style=3D"font-family:courier new,monospace"=
>identifier</span><Efoo,1>() { return u8"</span><span style=3D"f=
ont-family:courier new,monospace">baz</span><span style=3D"font-family:cour=
ier new,monospace">"; }<br>
</span><span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=C2=A0=
template<> constexpr Efoo enumerator_</span><span style=3D"font-fami=
ly:courier new,monospace"><span style=3D"font-family:courier new,monospace"=
>identifier</span><Efoo,2>() { return u8"</span><span style=3D"f=
ont-family:courier new,monospace">qux</span><span style=3D"font-family:cour=
ier new,monospace">"; }<br>
</span><span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=C2=A0=
template<> constexpr Efoo enumerator_</span><span style=3D"font-fami=
ly:courier new,monospace"><span style=3D"font-family:courier new,monospace"=
>identifier</span><Efoo,3>() { return u8"</span><span style=3D"f=
ont-family:courier new,monospace">e=CF=80</span><span style=3D"font-family:=
courier new,monospace">"; }<br>
</span><span style=3D"font-family:courier new,monospace">=C2=A0=C2=A0=C2=A0=
template<> constexpr Efoo enumerator_</span><span style=3D"font-fami=
ly:courier new,monospace"><span style=3D"font-family:courier new,monospace"=
>identifier</span><Efoo,4>() { return u8"</span><span style=3D"f=
ont-family:courier new,monospace">f\u03C0</span><span style=3D"font-family:=
courier new,monospace">"; }<br>
</span><span style=3D"font-family:courier new,monospace"><br>Using a std::i=
nteger_sequence it is possible to form an initializer list such as:<br><br>=
=C2=A0=C2=A0=C2=A0 std::multimap<Efoo, const char*> value_to_identifi=
er =3D { { enumerator_value<Efoo, i>(), enumerator_</span><span style=
=3D"font-family:courier new,monospace"><span style=3D"font-family:courier n=
ew,monospace">identifier</span><Efoo, i>() }... };<br>
<br>or<br><br>=C2=A0=C2=A0=C2=A0 std::map<std::string, Efoo> identifi=
er_to_value =3D { { enumerator_</span><span style=3D"font-family:courier ne=
w,monospace"><span style=3D"font-family:courier new,monospace">identifier</=
span><Efoo, i>(), enumerator_value<Efoo, i>() }... };<br>
<span style=3D"font-family:arial,sans-serif"><br>Because the elements of th=
e identifier string can be inspected in a constant expression, and because =
UTF-8 encodes all universal characters, it is possible to transcode the ide=
ntifier strings to any encoding during translation, as well as applying wha=
tever static checks on the enumerator values or identifiers that one may wa=
nt to apply.<br>
<br>Using <span style=3D"font-family:courier new,monospace">std::integer_se=
quence</span> it is also possible to form a pack consisting of the enumerat=
ors in declared order:<br><br><span style=3D"font-family:courier new,monosp=
ace">=C2=A0=C2=A0=C2=A0=C2=A0 template<Efoo... enumerator_pack><br>
=C2=A0=C2=A0=C2=A0=C2=A0 void f();<br><br>=C2=A0=C2=A0=C2=A0=C2=A0 f<enu=
merator_value<Efoo,i>()...>();<span class=3D"HOEnZb"><font color=
=3D"#888888"><br></font></span></span></span><span class=3D"HOEnZb"><font c=
olor=3D"#888888"><br></font></span></span><span class=3D"HOEnZb"><font colo=
r=3D"#888888"><span style=3D"font-family:courier new,monospace"></span></fo=
nt></span></div>
<span class=3D"HOEnZb"><font color=3D"#888888">
<p></p>
-- <br>
=C2=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 />
--e89a8f2355c73b276804e7ab25d7--
.
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Tue, 1 Oct 2013 03:44:20 -0700 (PDT)
Raw View
------=_Part_2863_31545313.1380624260646
Content-Type: text/plain; charset=ISO-8859-1
On Tuesday, October 1, 2013 12:08:56 PM UTC+2, Maurice Bos wrote:
>
> Why functions? Starting in C++14 we have variable templates, right?
>
A couple of (admittedly weak) reasons:
- The implementation may or may not want to leave the primary undefined
(for cases of non-enum E, or out-of-bounds i), and as far as I can tell
there is no nice way to not require a choice about that with a variable
template.
- While the ODR requirements are technically undefined, I am under the
impression that an instantiation of a variable template instantiation has a
worse chance of not ending up as a variable of static storage duration in
the translation unit. Clearly the temporary produced by the function will
not (but of course the functions themselves might, but I think this is less
likely). The intention is that the functions are only used during
translation, and constexpr functions seem better at this for some reason.
- For the `enumerator_identifier` to be a variable template it may mandate
the underlying array, whereas with a pointer returned from a constexpr
function this leaves it up to the implementation.
- There are no variable templates in the standard library that I am aware
of, and I didn't want to propose the first. :) I modelled it after limits
and traits to a certain extent.
On the otherside my list of the pros of making them variable templates
instead of function templates are empty, so decided to propose function
templates.
If you want to suggest some pros of variable templates over function
templates, be my guest. It wouldn't take much to change my mind about it.
--
---
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_2863_31545313.1380624260646
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, October 1, 2013 12:08:56 PM UTC+2, Maurice Bos=
wrote:<blockquote style=3D"margin: 0px 0px 0px 0.8ex; border-left: 1px sol=
id rgb(204, 204, 204); padding-left: 1ex;" class=3D"gmail_quote"><div dir=
=3D"ltr">Why functions? Starting in C++14 we have variable templates, right=
?<br></div></blockquote><br>A couple of (admittedly weak) reasons:<br><br>-=
The implementation may or may not want to leave the primary undefined (for=
cases of non-enum E, or out-of-bounds i), and as far as I can tell there i=
s no nice way to not require a choice about that with a variable template.<=
br><br>- While the ODR requirements are technically undefined, I am under t=
he impression that an instantiation of a variable template instantiation ha=
s a worse chance of not ending up as a variable of static storage duration =
in the translation unit. Clearly the temporary produced by the functi=
on will not (but of course the functions themselves might, but I think this=
is less likely). The intention is that the functions are only used d=
uring translation, and constexpr functions seem better at this for some rea=
son.<br><br>- For the `enumerator_identifier` to be a variable template it =
may mandate the underlying array, whereas with a pointer returned from a co=
nstexpr function this leaves it up to the implementation.<br><br>- There ar=
e no variable templates in the standard library that I am aware of, and I d=
idn't want to propose the first. :) I modelled it after limits and tr=
aits to a certain extent.<br><br>On the otherside my list of the pros of ma=
king them variable templates instead of function templates are empty, so de=
cided to propose function templates.<br><br>If you want to suggest some pro=
s of variable templates over function templates, be my guest. It woul=
dn't take much to change my mind about it.<br><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 />
------=_Part_2863_31545313.1380624260646--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 1 Oct 2013 14:11:10 +0300
Raw View
--089e0122797a9a1b9104e7ac02a1
Content-Type: text/plain; charset=ISO-8859-1
On 1 October 2013 13:44, Andrew Tomazos <andrewtomazos@gmail.com> wrote:
> On Tuesday, October 1, 2013 12:08:56 PM UTC+2, Maurice Bos wrote:
>>
>> Why functions? Starting in C++14 we have variable templates, right?
>>
>
> A couple of (admittedly weak) reasons:
>
> - The implementation may or may not want to leave the primary undefined
> (for cases of non-enum E, or out-of-bounds i), and as far as I can tell
> there is no nice way to not require a choice about that with a variable
> template.
>
> - While the ODR requirements are technically undefined, I am under the
> impression that an instantiation of a variable template instantiation has a
> worse chance of not ending up as a variable of static storage duration in
> the translation unit. Clearly the temporary produced by the function will
> not (but of course the functions themselves might, but I think this is less
> likely). The intention is that the functions are only used during
> translation, and constexpr functions seem better at this for some reason.
>
> - For the `enumerator_identifier` to be a variable template it may mandate
> the underlying array, whereas with a pointer returned from a constexpr
> function this leaves it up to the implementation.
>
> - There are no variable templates in the standard library that I am aware
> of, and I didn't want to propose the first. :) I modelled it after limits
> and traits to a certain extent.
>
> On the otherside my list of the pros of making them variable templates
> instead of function templates are empty, so decided to propose function
> templates.
>
> If you want to suggest some pros of variable templates over function
> templates, be my guest. It wouldn't take much to change my mind about it.
>
>
Just FYI, this is material for the Reflection Study Group, aka SG7. They
have their own mailing
list which is open to the public, should you want to discuss these things
there.
https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum/reflection
--
---
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/.
--089e0122797a9a1b9104e7ac02a1
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 1 October 2013 13:44, Andrew Tomazos <span dir=3D"ltr"><<a hr=
ef=3D"mailto:andrewtomazos@gmail.com" target=3D"_blank">andrewtomazos@gmail=
..com</a>></span> wrote:<br>
<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"><div cla=
ss=3D"im">On Tuesday, October 1, 2013 12:08:56 PM UTC+2, Maurice Bos wrote:=
<blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204=
,204,204);padding-left:1ex" class=3D"gmail_quote">
<div dir=3D"ltr">Why functions? Starting in C++14 we have variable template=
s, right?<br></div></blockquote><br></div>A couple of (admittedly weak) rea=
sons:<br><br>- The implementation may or may not want to leave the primary =
undefined (for cases of non-enum E, or out-of-bounds i), and as far as I ca=
n tell there is no nice way to not require a choice about that with a varia=
ble template.<br>
<br>- While the ODR requirements are technically undefined, I am under the =
impression that an instantiation of a variable template instantiation has a=
worse chance of not ending up as a variable of static storage duration in =
the translation unit.=A0 Clearly the temporary produced by the function wil=
l not (but of course the functions themselves might, but I think this is le=
ss likely).=A0 The intention is that the functions are only used during tra=
nslation, and constexpr functions seem better at this for some reason.<br>
<br>- For the `enumerator_identifier` to be a variable template it may mand=
ate the underlying array, whereas with a pointer returned from a constexpr =
function this leaves it up to the implementation.<br><br>- There are no var=
iable templates in the standard library that I am aware of, and I didn'=
t want to propose the first. :)=A0 I modelled it after limits and traits to=
a certain extent.<br>
<br>On the otherside my list of the pros of making them variable templates =
instead of function templates are empty, so decided to propose function tem=
plates.<br><br>If you want to suggest some pros of variable templates over =
function templates, be my guest.=A0 It wouldn't take much to change my =
mind about it.<br>
<br></div></blockquote><div><br><br></div><div>Just FYI, this is material f=
or the Reflection Study Group, aka SG7. They have their own mailing<br>list=
which is open to the public, should you want to discuss these things there=
..<br>
<a href=3D"https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum/=
reflection">https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum=
/reflection</a> <br></div></div><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" 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 />
--089e0122797a9a1b9104e7ac02a1--
.
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Tue, 1 Oct 2013 04:27:15 -0700 (PDT)
Raw View
------=_Part_148_18657387.1380626835343
Content-Type: text/plain; charset=ISO-8859-1
On Tuesday, October 1, 2013 1:11:10 PM UTC+2, Ville Voutilainen wrote:
>
> Just FYI, this is material for the Reflection Study Group, aka SG7. They
> have their own mailing
> list which is open to the public, should you want to discuss these things
> there.
> https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum/reflection
>
>
Ok, I'll cross-post the OP there.
--
---
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_148_18657387.1380626835343
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, October 1, 2013 1:11:10 PM UTC+2, Vill=
e Voutilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">Just FYI, this is material for the Reflection Study Group, aka SG7=
.. They have their own mailing<br><div><div class=3D"gmail_quote"><div>list =
which is open to the public, should you want to discuss these things there.=
<br>
<a href=3D"https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum/=
reflection" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/f=
orum/?fromgroups#!<wbr>forum/reflection</a> <br></div></div><br></div></div=
></blockquote><div><br>Ok, I'll cross-post the OP there.<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" 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_148_18657387.1380626835343--
.