Topic: Size deduction for std::array from initializer:
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 9 Mar 2015 12:17:24 -0700 (PDT)
Raw View
------=_Part_889_1714935834.1425928644945
Content-Type: multipart/alternative;
boundary="----=_Part_890_1548535651.1425928644945"
------=_Part_890_1548535651.1425928644945
Content-Type: text/plain; charset=UTF-8
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3824.htm
It seems that without being able to forward braced initializers this
solution to "non-type template argument deduction" via a varidic make
function is incomplete.
struct Point { double x; double y; }
//n3824 forces us to do this:
auto a = make_array(Point{1.0, 2.0}, Point{3.0, 4.0});
//Should be able to do something like this:
auto a = make_array<Point>( { 1.0, 2.0 }, { 3.0, 4.0 });
//This would be ok too
auto a = make_array<Point>({{1.0, 2.0}, {3.0, 4.0}});
//This might be ideal
std::array<Point,/*what goes here?*/> a = {{1.0, 2.0}, {3.0, 4.0}};
//For initialization, C array is still superior
Point a[] = {{1.0, 2.0}, {3.0, 4.0}};
For a large array, typing Point{..} every time is redundant and also makes
refactoring more painful.
Are we sure this is the direction we want to go in? Is it really a good
thing that initializing a C array and initializing a std::array with size
deduction use different syntax with completely different rules? I can
initialize a C array with braced initializers but I can't do it with
std::array.
Somewhat related, there are also issues with declaring and defining static
data members with auto. Since we need to use auto with std::make_array, we
also run into this problem:
class A {
static constexpr auto a = make_array(1, 2, 3);
};
constexpr decltype(A::a) A::a; //Ugly, but it works
template <typename T>
class B {
static constexpr auto b = make_array(1, 2, 3);
};
template <typename T>
constexpr decltype(B<T>::b) B<T>::b; //This is a compiler error (it works
on some versions of gcc, doesn't work on clang, and according to standard
should fail).
As far as I can tell, there is no standard compliant way to write a
definition for B<T>::b without writing the exact type. The current
workaround is to define the constants in a non-template base class and
inherit publicly.
One solution could be to reuse [] (or any other symbol which doesn't break
legacy code):
struct A {
static constexpr std::array<Point,[]> a = {{1.0, 2.0}, {3.0, 4.0}}; //Value
of [] is deduced by number of initializers
};
constexpr std::array<Point,[]> A::a; //Looks for declaration to deduce [],
compiler error if none can be found.
constexpr std::array<Point,[]> b; //Compiler error, deducing [] requires
either an initializer or a previous declaration with an initializer.
and if another proposal enables auto in template parameters, we can do this:
std::array<auto,[]> = { 1, 2, 3}; //is std::array<int,3>
--
---
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_890_1548535651.1425928644945
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/pap=
ers/2014/n3824.htm">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014=
/n3824.htm</a><br><br>It seems that without being able to forward braced in=
itializers this solution to "non-type template argument deduction" via a va=
ridic make function is incomplete.<br><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 clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;=
" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Point</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">double</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">double</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> y</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"></span><br><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><code class=3D"prett=
yprint"><span style=3D"color: #800;" class=3D"styled-by-prettify">//n3824 f=
orces us to do this:</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> make_array</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">Point</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">1.0</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">2.0</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: #606;" class=3D"styled-by-prettify">Point</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span =
style=3D"color: #066;" class=3D"styled-by-prettify">3.0</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" =
class=3D"styled-by-prettify">4.0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">});</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span></code><br></span><span style=3D"color: #800;" =
class=3D"styled-by-prettify">//Should be able to do something like this:</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> a </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> make_array</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #606;=
" class=3D"styled-by-prettify">Point</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">>(</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">1.0</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">2.0</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">},</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">3.0</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #066;" class=3D"styled-by-prettify">4.0</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">});</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br><br></span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">//This would be ok too</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> a </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> make_array</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify">P=
oint</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>({=
{</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1.0</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #066;" class=3D"styled-by-prettify">2.0</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">},</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">{</span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">3.0</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #066;" class=3D"styled-by-prettify">4.0</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}});</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">//This might be ideal</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">array</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: =
#606;" class=3D"styled-by-prettify">Point</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">,</span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">/*what goes here?*/</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> a </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">{{</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1.0<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">2.0</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">},</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">3.0</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: #066;" class=3D"styled-by-prettify">4.0</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}};</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">//For initialization, C ar=
ray is still superior</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">Point</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[]</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">{{</span><span style=3D"color: #066;" cla=
ss=3D"styled-by-prettify">1.0</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify"=
>2.0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">},</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"=
color: #066;" class=3D"styled-by-prettify">3.0</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"st=
yled-by-prettify">4.0</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}};</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span></div></code></div><br>For a large array, typing Point{..} e=
very time is redundant and also makes refactoring more painful.<br><br>Are =
we sure this is the direction we want to go in? Is it really a good=20
thing that initializing a C array and initializing a std::array with size d=
eduction use=20
different syntax with completely different rules? I can initialize a C arra=
y with braced initializers but I can't do it with std::array.<br><br><br>So=
mewhat related, there are also issues with declaring and defining static da=
ta members with auto. Since we need to use auto with std::make_array, we al=
so run into this problem:<br><br><div class=3D"prettyprint" style=3D"backgr=
ound-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-st=
yle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D=
"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> A </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>static</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> a </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> make_array</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #066;" clas=
s=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">2<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
decltype</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">A</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">a</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #800;" class=3D"styled-by-prettify">//Ugly, but it=
works</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
<br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">templa=
te</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> B </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">static</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">con=
stexpr</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> b </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> make_array</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pre=
ttify">2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">template</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">B</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">>::</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">b</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> B</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">>::</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">b</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"styl=
ed-by-prettify">//This is a compiler error (it works on some versions of gc=
c, doesn't work on clang, and according to standard should fail).</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></c=
ode></div><br>As far as I can tell, there is no standard compliant way to w=
rite a definition for B<T>::b without writing the exact type. The cur=
rent workaround is to define the constants in a non-template base class and=
inherit publicly.<br><br>One solution could be to reuse [] (or any other s=
ymbol which doesn't break legacy code):<br><br><div class=3D"prettyprint" s=
tyle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 1=
87); border-style: solid; border-width: 1px; word-wrap: break-word;"><code =
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> A </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">static</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">array</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">Point</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,[]></span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> a </span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">{{</span><span style=3D"color: #066;" class=3D"styled-=
by-prettify">1.0</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #066;" class=3D"styled-by-prettify">2.0</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">},</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #066;"=
class=3D"styled-by-prettify">3.0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">4.0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #800;" class=3D"styled-by-prettify">//Value of [] is =
deduced by number of initializers</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">array</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span=
style=3D"color: #606;" class=3D"styled-by-prettify">Point</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">,[]></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">a</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">//Looks for declaration to deduce [], compiler error if none can be f=
ound.</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">constex=
pr</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">array</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Point</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">,[]></span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> b</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pr=
ettify">//Compiler error, deducing [] requires either an initializer or a p=
revious declaration with an initializer.</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span></div></code></div><br>and if anot=
her proposal enables auto in template parameters, we can do this:<br><br><d=
iv class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bor=
der-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word=
-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprin=
t"><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">array</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">,[]></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">2</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">3</span><span style=3D"color: #660;" class=3D"styled-by-prettify">};<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #800;" class=3D"styled-by-prettify">//is std::array<i=
nt,3></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span></div></code></div><br><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 <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_890_1548535651.1425928644945--
------=_Part_889_1714935834.1425928644945--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Mon, 9 Mar 2015 16:15:13 -0400
Raw View
On Mon, Mar 9, 2015 at 3:17 PM, Matthew Fioravante
<fmatthew5876@gmail.com> wrote:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3824.htm
>
> It seems that without being able to forward braced initializers this
> solution to "non-type template argument deduction" via a varidic make
> function is incomplete.
>
> struct Point { double x; double y; }
>
> //n3824 forces us to do this:
> auto a = make_array(Point{1.0, 2.0}, Point{3.0, 4.0});
>
> //Should be able to do something like this:
> auto a = make_array<Point>( { 1.0, 2.0 }, { 3.0, 4.0 });
>
The problem of unable to perfect forward braced-init list
is a problem with uniform initialization itself, and applies
to everywhere, not limited to make_array, nor make_*.
If you want to solve it, go solve it.
> Is it really a good
> thing that initializing a C array and initializing a std::array with size
> deduction use different syntax with completely different rules?
Not "completely". While the language can do something
that library cannot, you will always have caveats, in lots
of places. But if we choose not to make a progress, we
are probably having bigger issues.
>
> class A {
> static constexpr auto a = make_array(1, 2, 3);
> };
> constexpr decltype(A::a) A::a; //Ugly, but it works
>
> template <typename T>
> class B {
> static constexpr auto b = make_array(1, 2, 3);
> };
> template <typename T>
> constexpr decltype(B<T>::b) B<T>::b; //This is a compiler error (it works on
> some versions of gcc, doesn't work on clang, and according to standard
> should fail).
>
Sorry I don't know why this doesn't work. More like
clang's problem to me.
> and if another proposal enables auto in template parameters, we can do this:
>
> std::array<auto,[]> = { 1, 2, 3}; //is std::array<int,3>
>
Even with that proposal, it still may not work
because { ... } with auto will very likely be deduced
to std::initializer_list<int>, or simply not supported,
but std::array is required to have no (user-declared)
constructor.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://bit.ly/blog4bsd
--
---
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/.
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 9 Mar 2015 13:42:09 -0700 (PDT)
Raw View
------=_Part_3879_1433758727.1425933729168
Content-Type: multipart/alternative;
boundary="----=_Part_3880_268921702.1425933729168"
------=_Part_3880_268921702.1425933729168
Content-Type: text/plain; charset=UTF-8
On Monday, March 9, 2015 at 4:15:16 PM UTC-4, Zhihao Yuan wrote:
>
> On Mon, Mar 9, 2015 at 3:17 PM, Matthew Fioravante
> <fmatth...@gmail.com <javascript:>> wrote:
> > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3824.htm
> >
> > It seems that without being able to forward braced initializers this
> > solution to "non-type template argument deduction" via a varidic make
> > function is incomplete.
> >
> > struct Point { double x; double y; }
> >
> > //n3824 forces us to do this:
> > auto a = make_array(Point{1.0, 2.0}, Point{3.0, 4.0});
> >
> > //Should be able to do something like this:
> > auto a = make_array<Point>( { 1.0, 2.0 }, { 3.0, 4.0 });
> >
>
> The problem of unable to perfect forward braced-init list
> is a problem with uniform initialization itself, and applies
> to everywhere, not limited to make_array, nor make_*.
> If you want to solve it, go solve it.
>
Accepting make_array() is assuming that this problem will either be solved
in the future or that its good enough having to live with it never being
solved. Or is the standards committee ok with something now that might be
obsoleted in the future should a better solution be found?
>
> > Is it really a good
> > thing that initializing a C array and initializing a std::array with
> size
> > deduction use different syntax with completely different rules?
>
> Not "completely". While the language can do something
> that library cannot, you will always have caveats, in lots
> of places. But if we choose not to make a progress, we
> are probably having bigger issues.
>
I'm concerned that we may be taking the wrong direction. If a language
feature is invented to initialize std::array (and other similar templates)
then make_array() may not be needed at all. A language feature also solves
this problem for all possible template classes with non-type template size
parameters. The make_array() approach means having to write a new make_X()
method for each template class which might need it. Looking at your example
implementation, writing ones own make_X() is non-trivial with all of the
edge cases covered by type_traits.
>
> >
> > class A {
> > static constexpr auto a = make_array(1, 2, 3);
> > };
> > constexpr decltype(A::a) A::a; //Ugly, but it works
> >
> > template <typename T>
> > class B {
> > static constexpr auto b = make_array(1, 2, 3);
> > };
> > template <typename T>
> > constexpr decltype(B<T>::b) B<T>::b; //This is a compiler error (it
> works on
> > some versions of gcc, doesn't work on clang, and according to standard
> > should fail).
> >
>
> Sorry I don't know why this doesn't work. More like
> clang's problem to me.
>
>
From what I've found in my research (below bug report and an SO question
which I cannot find now), this is standard mandated behavior. Gcc is wrong
to accept it.
http://lists.cs.uiuc.edu/pipermail/llvmbugs/2013-January/026679.html
This issue however might be fixable with its own proposal.
> > and if another proposal enables auto in template parameters, we can do
> this:
> >
> > std::array<auto,[]> = { 1, 2, 3}; //is std::array<int,3>
> >
>
> Even with that proposal, it still may not work
> because { ... } with auto will very likely be deduced
> to std::initializer_list<int>, or simply not supported,
> but std::array is required to have no (user-declared)
> constructor.
>
This is not really a problem. If you just write a braced initializer and
say auto the compiler of course has no idea what you want. If you want
points you must say Point somewhere (hopefully only once).
--
---
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_3880_268921702.1425933729168
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, March 9, 2015 at 4:15:16 PM UTC-4, Zhih=
ao Yuan wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Mon, Mar 9, 2=
015 at 3:17 PM, Matthew Fioravante
<br><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
xf_d8IpPajkJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';ret=
urn true;" onclick=3D"this.href=3D'javascript:';return true;">fmatth...@gma=
il.com</a>> wrote:
<br>> <a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014=
/n3824.htm" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
http://www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2=
Fwg21%2Fdocs%2Fpapers%2F2014%2Fn3824.htm\46sa\75D\46sntz\0751\46usg\75AFQjC=
NEhx1e9tIZMmvWN5XDo2AJKkX3rJw';return true;" onclick=3D"this.href=3D'http:/=
/www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%=
2Fdocs%2Fpapers%2F2014%2Fn3824.htm\46sa\75D\46sntz\0751\46usg\75AFQjCNEhx1e=
9tIZMmvWN5XDo2AJKkX3rJw';return true;">http://www.open-std.org/jtc1/<wbr>sc=
22/wg21/docs/papers/2014/<wbr>n3824.htm</a>
<br>>
<br>> It seems that without being able to forward braced initializers th=
is
<br>> solution to "non-type template argument deduction" via a varidic m=
ake
<br>> function is incomplete.
<br>>
<br>> struct Point { double x; double y; }
<br>>
<br>> //n3824 forces us to do this:
<br>> auto a =3D make_array(Point{1.0, 2.0}, Point{3.0, 4.0});
<br>>
<br>> //Should be able to do something like this:
<br>> auto a =3D make_array<Point>( { 1.0, 2.0 }, { 3.0, 4.0 });
<br>>
<br>
<br>The problem of unable to perfect forward braced-init list
<br>is a problem with uniform initialization itself, and applies
<br>to everywhere, not limited to make_array, nor make_*.
<br>If you want to solve it, go solve it.
<br></blockquote><div><br>Accepting make_array() is assuming that this prob=
lem will either be solved in the future or that its good enough having to l=
ive with it never being solved. Or is the standards committee ok with somet=
hing now that might be obsoleted in the future should a better solution be =
found?<br> </div><blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>> Is it really a good
<br>> thing that initializing a C array and initializing a std::array wi=
th size
<br>> deduction use different syntax with completely different rules?
<br>
<br>Not "completely". While the language can do something
<br>that library cannot, you will always have caveats, in lots
<br>of places. But if we choose not to make a progress, we
<br>are probably having bigger issues.
<br></blockquote><div><br>I'm concerned that we may be taking the wrong dir=
ection. If a language feature is invented to initialize std::array (and oth=
er similar templates) then make_array() may not be needed at all. A languag=
e feature also solves this problem for all possible template classes with n=
on-type template size parameters. The make_array() approach means having to=
write a new make_X() method for each template class which might need it. L=
ooking at your example implementation, writing ones own make_X() is non-tri=
vial with all of the edge cases covered by type_traits.<br> </div><blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;">
<br>>
<br>> class A {
<br>> static constexpr auto a =3D make_array(1, 2, 3);
<br>> };
<br>> constexpr decltype(A::a) A::a; //Ugly, but it works
<br>>
<br>> template <typename T>
<br>> class B {
<br>> static constexpr auto b =3D make_array(1, 2, 3);
<br>> };
<br>> template <typename T>
<br>> constexpr decltype(B<T>::b) B<T>::b; //This is a compi=
ler error (it works on
<br>> some versions of gcc, doesn't work on clang, and according to stan=
dard
<br>> should fail).
<br>>
<br>
<br>Sorry I don't know why this doesn't work. More like
<br>clang's problem to me.
<br>
<br></blockquote><div><br>From what I've found in my research (below bug re=
port and an SO question which I cannot find now), this is standard mandated=
behavior. Gcc is wrong to accept it.<br><br>http://lists.cs.uiuc.edu/piper=
mail/llvmbugs/2013-January/026679.html<br><br>This issue however might be f=
ixable with its own proposal.<br> </div><blockquote class=3D"gmail_quo=
te" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddi=
ng-left: 1ex;">> and if another proposal enables auto in template parame=
ters, we can do this:
<br>>
<br>> std::array<auto,[]> =3D { 1, 2, 3}; //is std::array<int,3=
>
<br>>
<br>
<br>Even with that proposal, it still may not work
<br>because { ... } with auto will very likely be deduced
<br>to std::initializer_list<int>, or simply not supported,
<br>but std::array is required to have no (user-declared)
<br>constructor.
<br></blockquote><div><br>This is not really a problem. If you just write a=
braced initializer and say auto the compiler of course has no idea what yo=
u want. If you want points you must say Point somewhere (hopefully only onc=
e).
</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 <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_3880_268921702.1425933729168--
------=_Part_3879_1433758727.1425933729168--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Mon, 9 Mar 2015 17:41:01 -0400
Raw View
On Mon, Mar 9, 2015 at 4:42 PM, Matthew Fioravante
<fmatthew5876@gmail.com> wrote:
>
> Accepting make_array() is assuming that this problem will either be solved
> in the future or that its good enough having to live with it never being
> solved.
Nope. It simply means the new addition solves the problem
it's trying to solve.
> Or is the standards committee ok with something now that might be
> obsoleted in the future should a better solution be found?
>
No either, because make_array has its unique use cases.
For example, a language level solution cannot produce a
common type out of a braced-init:
std::array<auto,[]> a = { 'a', 10 }; // boom
auto a = make_array('a', 10);
>
> I'm concerned that we may be taking the wrong direction. If a language
> feature is invented to initialize std::array (and other similar templates)
> then make_array() may not be needed at all.
It's committee's job to decide direction. I think we have
done with the technical issues here.
> The make_array() approach means having to write a new make_X()
> method for each template class which might need it.
Short, flexible, and works for me.
> Looking at your example
> implementation, writing ones own make_X() is non-trivial with all of the
> edge cases covered by type_traits.
>
You might want to take a closer look. They are "features"
which cannot be provided with language extensions.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://bit.ly/blog4bsd
--
---
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/.
.