220 16915 <6e1bae2e-8173-4437-a45b-63cddab072e5@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Fioravante <fmatthew5876@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Size deduction for std::array from initializer:
 Comments on n3824 std::make_array
Date: Mon, 9 Mar 2015 13:42:09 -0700 (PDT)
Lines: 248
Approved: news@gmane.org
Message-ID: <6e1bae2e-8173-4437-a45b-63cddab072e5@isocpp.org>
References: <7a747557-95d6-4484-a7d8-f18fcb05ee59@isocpp.org>
 <CAGsORuCBX1agar_iHvieDGfO6HH30gGP3_cp=m1K89+068DYOA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3879_1433758727.1425933729168"
X-Trace: ger.gmane.org 1425933736 1195 80.91.229.3 (9 Mar 2015 20:42:16 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 9 Mar 2015 20:42:16 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDELF54RTIGRBIML7CTQKGQEUAGBSWI@isocpp.org Mon Mar 09 21:42:11 2015
Return-path: <std-proposals+bncBDELF54RTIGRBIML7CTQKGQEUAGBSWI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f197.google.com ([209.85.216.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDELF54RTIGRBIML7CTQKGQEUAGBSWI@isocpp.org>)
	id 1YV4V8-0006s5-UZ
	for gclcip-std-proposals@m.gmane.org; Mon, 09 Mar 2015 21:42:11 +0100
Original-Received: by qcyl6 with SMTP id l6sf43892546qcy.1
        for <gclcip-std-proposals@m.gmane.org>; Mon, 09 Mar 2015 13:42:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :content-type:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=yZtAzhnrGX4SPzWMfI+wZ/Ts1qQfIwRvhdNZQDPb2/Q=;
        b=rw3ByuMlnjnceQ6tv6TSSWrpkTcayI9qK5xMTf9CwDG5criBYeebNjxlcoxo6d2b+I
         UIzVcQsW0ayU6UU8qsRKKVCbvkcBvIkL3AMdHP3mZ/IqrgqLY9hgKj60Sjmm9+oKw8JJ
         Xo+JEbshxzBncWGu1jgmzb2mf31AMEcEkE/uQyUkg2Z8RjD66Tk4ngw2vlRg8t7HEqlM
         UWuXDvKO4RbmFFoME/cI+MtIITvYw5uur+U97rTGaoiIGpS8uN+3Mb32QANw6UOdr/Wu
         0CqhKWhLKSeTHpNisioEo3jQUjAeNcVs/Q+Hl7HDzK5ja/kOQkQPXdNEv7VKMFnhWH9y
         DwSg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=yZtAzhnrGX4SPzWMfI+wZ/Ts1qQfIwRvhdNZQDPb2/Q=;
        b=A8DM7+bzf6Z+iEXB2BvcvKDJh52j5+pHKSSWo2UchzvP/QS+PKoE2fR8HuvXpy/8LA
         Ux5GSShO7u2zJjll6R+f1epi88NnMVv0i/lqtw16hg35p+AELcWCRdCTwofzAS4MLejh
         uWrLejGkuLVMzOzjFkbQDHb+N3lMrwZTNOr98kNfrCkE04DjUtcs5WS+SOscpmMmo3Es
         sy/4CqkRh8Gg2yvIsIrODJZAWnnmgFl2dDd2r5zZcMHDdrikcQ4aCdyadjqkkcLdOSHq
         sIuMTrZ9fxQotyhdsya8svP7Q0Gm2wDfh1NLdNiiaPxLJV7XEVIngO5eNjVtak9QWE0b
         n31w==
X-Gm-Message-State: ALoCoQm4tHIP/g+KBikji3cnij1wZua136DCgJCjTT5zroOwfjYNnQa7GaFLqkyG09DuXT+AAO3T
X-Received: by 10.236.2.35 with SMTP id 23mr28272558yhe.22.1425933730039;
        Mon, 09 Mar 2015 13:42:10 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.31.102 with SMTP id e93ls1595873qge.87.gmail; Mon, 09 Mar
 2015 13:42:09 -0700 (PDT)
X-Received: by 10.140.33.202 with SMTP id j68mr485537qgj.27.1425933729539;
        Mon, 09 Mar 2015 13:42:09 -0700 (PDT)
In-Reply-To: <CAGsORuCBX1agar_iHvieDGfO6HH30gGP3_cp=m1K89+068DYOA@mail.gmail.com>
X-Original-Sender: fmatthew5876@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:16915
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/16915>

------=_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>&lt;<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>&gt; wrote:
<br>&gt; <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>&gt;
<br>&gt; It seems that without being able to forward braced initializers th=
is
<br>&gt; solution to "non-type template argument deduction" via a varidic m=
ake
<br>&gt; function is incomplete.
<br>&gt;
<br>&gt; struct Point { double x; double y; }
<br>&gt;
<br>&gt; //n3824 forces us to do this:
<br>&gt; auto a =3D make_array(Point{1.0, 2.0}, Point{3.0, 4.0});
<br>&gt;
<br>&gt; //Should be able to do something like this:
<br>&gt; auto a =3D make_array&lt;Point&gt;( { 1.0, 2.0 }, { 3.0, 4.0 });
<br>&gt;
<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>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>&gt; Is it really a good
<br>&gt; thing that initializing a C array and initializing a std::array wi=
th size
<br>&gt; deduction use different syntax with completely different rules?
<br>
<br>Not "completely". &nbsp;While the language can do something
<br>that library cannot, you will always have caveats, in lots
<br>of places. &nbsp;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>&nbsp;</div><blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;">
<br>&gt;
<br>&gt; class A {
<br>&gt; &nbsp; static constexpr auto a =3D make_array(1, 2, 3);
<br>&gt; };
<br>&gt; constexpr decltype(A::a) A::a; //Ugly, but it works
<br>&gt;
<br>&gt; template &lt;typename T&gt;
<br>&gt; class B {
<br>&gt; &nbsp; static constexpr auto b =3D make_array(1, 2, 3);
<br>&gt; };
<br>&gt; template &lt;typename T&gt;
<br>&gt; constexpr decltype(B&lt;T&gt;::b) B&lt;T&gt;::b; //This is a compi=
ler error (it works on
<br>&gt; some versions of gcc, doesn't work on clang, and according to stan=
dard
<br>&gt; should fail).
<br>&gt;
<br>
<br>Sorry I don't know why this doesn't work. &nbsp;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>&nbsp;</div><blockquote class=3D"gmail_quo=
te" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddi=
ng-left: 1ex;">&gt; and if another proposal enables auto in template parame=
ters, we can do this:
<br>&gt;
<br>&gt; std::array&lt;auto,[]&gt; =3D { 1, 2, 3}; //is std::array&lt;int,3=
&gt;
<br>&gt;
<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&lt;int&gt;, 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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3880_268921702.1425933729168--
------=_Part_3879_1433758727.1425933729168--

.
