220 5736 <bb038937-a519-49fc-ab32-373f6438e77b@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Uniform intialization with std::intializer_list
 is not uniform.
Date: Wed, 14 Aug 2013 16:59:13 -0700 (PDT)
Lines: 202
Approved: news@gmane.org
Message-ID: <bb038937-a519-49fc-ab32-373f6438e77b@isocpp.org>
References: <ab2d2158-d08c-4fdc-914f-df698e4f7b7c@isocpp.org>
 <CAGNvRgDyVZRfr5MZ3nMHPvjhW96tGbEpMHd9GKKspvdB4PMggg@mail.gmail.com>
 <CAFk2RUbGsghsRCs8mNhTgAbUHyxY5Zrk5kzRWbJ7VY6qMk0ZfQ@mail.gmail.com>
 <CAGNvRgALbHCdb+ithwL-ZsV2O3tcXTRy6QAV-82DoZPxikJ=oA@mail.gmail.com>
 <CAFk2RUb6eOhgbPSgwPHVJ=bnTSjOVo8k5UWCpFD1X6D0DbhoSg@mail.gmail.com>
 <CAGNvRgBMttU2LvJBWCNecTpPHuz9ujUmOEdhyXwr1b3J5SY2MA@mail.gmail.com>
 <CAFk2RUauNpfMQ9th5B7pFFyodZ78hfoJ4O8RNPqgai0Zg=rbvA@mail.gmail.com>
 <CAGNvRgBE3X9BF-6RnCmMMdGY9pNza3n0nFWcSTjzqF5LDx9ROA@mail.gmail.com>
 <CAFk2RUbX7SFj8yeM_qNA2XhfgNfGkS_bUu+_8DiewhGkdF_Ncw@mail.gmail.com>
 <CAGNvRgB7tqttBqt56RTvVzRdOVtv-dz1d-YhMESHi1RmurUjmQ@mail.gmail.com>
 <CAFk2RUbuxGj1__ff-yUmrpw+jEgZowv6vW42PVNhdav6A2uu+w@mail.gmail.com>
 <e4a61b96-c31c-4f16-b924-598b758b63b9@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_2999_31542940.1376524753480"
X-Trace: ger.gmane.org 1376524756 22256 80.91.229.3 (14 Aug 2013 23:59:16 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 14 Aug 2013 23:59:16 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBU5TWCIAKGQETA2Q2UI@isocpp.org Thu Aug 15 01:59:18 2013
Return-path: <std-proposals+bncBCEKFTV6ZUMBBU5TWCIAKGQETA2Q2UI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f71.google.com ([209.85.219.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBU5TWCIAKGQETA2Q2UI@isocpp.org>)
	id 1V9kyD-0004aP-JJ
	for gclcip-std-proposals@m.gmane.org; Thu, 15 Aug 2013 01:59:17 +0200
Original-Received: by mail-oa0-f71.google.com with SMTP id k18sf471327oag.6
        for <gclcip-std-proposals@m.gmane.org>; Wed, 14 Aug 2013 16:59:16 -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
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=X468FC4OPQHW23T/HCDAheOQKo4rpiU0gGxl/QsH7WE=;
        b=Z5zcxYv5ZBaxS69QeZDYCiQ/M9OKEW15RCKg123mw8XcbBBe1R13LU2inzdJjcmVlt
         kaklt8Giq1gfSQyzwaJpSiDMo/NsWwExcejGWOYzfl6aLT01CCPgtyZxwlWoSPFGZUj4
         bvYa21NTbUSHiMgpCDYfJDH15FztK5G/8yuXtWZDUevQd5Eaw3Z9mqVo59s6qDGE49k3
         HoZqdnIfvQck497X46ACTVIkyWcqls9sxrxXjKCUtt+XNYJJn62PD6dhY4aIrBpUBbDU
         ZIX/FfUddBlyndTlCcpWBgheBxz1x+JOT3pTJrifWqc1uGS6ukqS/ovYMNUi9GHvaM0t
         fwzg==
X-Received: by 10.42.70.138 with SMTP id f10mr7023537icj.16.1376524756552;
        Wed, 14 Aug 2013 16:59:16 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.107.9 with SMTP id gy9ls2224183igb.9.canary; Wed, 14 Aug
 2013 16:59:15 -0700 (PDT)
X-Received: by 10.50.29.72 with SMTP id i8mr8548igh.1.1376524755652;
        Wed, 14 Aug 2013 16:59:15 -0700 (PDT)
In-Reply-To: <e4a61b96-c31c-4f16-b924-598b758b63b9@isocpp.org>
X-Original-Sender: jmckesson@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:5736
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/5736>

------=_Part_2999_31542940.1376524753480
Content-Type: text/plain; charset=ISO-8859-1

On Wednesday, August 14, 2013 1:42:38 PM UTC-7, toma...@gmail.com wrote:
>
> That's ok, I don't know what the solution should be yet, perhaps
>> mutating initializer_list isn't it. The problem shouldn't be "this is how
>> initializer_lists work, don't expect braced-initializers to work 
>> differently".
>> I'm not supposed to KNOW there's an initializer_list involved when
>> I construct a vector from a braced list. At least I'm under the impression
>> that initializer_list was supposed to be implementation plumbing
>> rather than something that's in-my-face. And again, I don't think
>> that implementation plumbing works quite right if I can't braced-init
>> with move-only types. Other people can freely agree to disagree
>> with that.
>>  
>>
> The std::initializer_list<int> is only the solution of the uniform 
> initialization problem,
> not the problem itself. So while the design of initializer list is 
> perfectly valid (thanks
> Daniel for the papers), this model failed to achieve the main goal:
>
> Provide uniform initialization for build-in types (arrays) and
> user defined types.
>

No. Uniform initialization was about the copy vs. direct vs. aggregate 
initialization paradigm. That is, providing a single way to initialize a 
type that works exactly the same in all circumstances, which can be used 
for all types. But because it used {} syntax, it was also adopted into 
providing a way to initialize an arbitrary object from a sequence of 
equivalently typed parameters. But that wasn't its primary purpose.

That is the slogan/promotional phase for the most of materials about C++11.
> But the initialization of the vector is not uniform with the build-in 
> arrays, which
> is suprising for the users and make learning of C++ harder, not easer as 
> uniform initialization suppose to. Especially when no 
> presentation/material know to me
> on C++11 mentions this - they use the slogan.
>
 
That's because it's fairly minor, all things considered. The far more 
eggregious issue with UI is that initializer_list constructors can hide 
constructors that just so happen to take the same types of parameters. The 
fact that you can't put a non-copyable type in a braced-init-list that will 
be converted into an initializer_list is pretty minor next to hiding 
important constructors, thus forcing you back into () constructor syntax.
 

> *Was another approach possible?*
> I think yes. To point is to not use 2-face initialization and use 
> varidatic templates instead:
>

Um, how does that help? It now turns something that was quite simple into 
something incredibly complex. Yes, it solves one problem, but it creates 
many more.

It makes accidental narrowing very possible. It makes the compiler errors 
you get for creating a braced-init-list of different types much more 
oddball. It causes the generation of lots of pointless code, bloating 
compile times needlessly (it's a list of known size. We shouldn't have to 
template metaprogram recurse through it). It also conflicts with other 
parts of uniform initialization: being able to call non-initializer_list 
constructors with braced-init-lists.** Lastly, there's no way to 
differentiate between a variadic template intended for some other purpose 
and an object that you want to be constructed from an arbitrary list of 
values.
 

> Of course this code needs allocator support (std::allocator_arg should be 
> used), but this
> is doable.
>
> This will of course make writing an STL-like container even harder, but 
> the allocator support
> and exception safety already make this a really hrd task so that should 
> not be a problem. Also
> there will be some problem with ambiguity of constructor. But from the 
> user perspective the goal will
> be achived - the vector intialization will be uniform with intialization 
> of build in arrays, even considering
> performance.
>

There are a lot more uses for having an object with an initializer_list 
constructor than *just* an STL-compliant container type. We shouldn't make 
you have to go through that much effort to process *an array*.

As people have said, this is a solveable problem. We may need a new 
"initializer_list" type to solve it, but it can certainly be resolved under 
the existing paradigm.

-- 

--- 
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_2999_31542940.1376524753480
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, August 14, 2013 1:42:38 PM UTC-7, toma...@gm=
ail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bord=
er-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=
=3D"gmail_quote"><div></div><div>That's ok, I don't know what the solution =
should be yet, perhaps<br>mutating initializer_list isn't it. The problem s=
houldn't be "this is how<br>initializer_lists work, don't expect braced-ini=
tializers to work differently".<br>
</div><div>I'm not supposed to KNOW there's an initializer_list involved wh=
en<br></div><div>I construct a vector from a braced list. At least I'm unde=
r the impression<br>that initializer_list was supposed to be implementation=
 plumbing<br>
rather than something that's in-my-face. And again, I don't think<br>that i=
mplementation plumbing works quite right if I can't braced-init<br>with mov=
e-only types. Other people can freely agree to disagree<br>
with that.<br>&nbsp;</div></div></div></div></blockquote><div>The std::init=
ializer_list&lt;int&gt; is only the solution of the uniform initialization =
problem,<br>not the problem itself. So while the design of initializer list=
 is perfectly valid (thanks<br>Daniel for the papers), this model failed to=
 achieve the main goal:<br><span style=3D"font-family:courier new,monospace=
"><br>Provide uniform initialization for build-in types (arrays) and<br>use=
r defined types.<br></span></div></div></blockquote><div><br>No. Uniform in=
itialization was about the copy vs. direct vs. aggregate=20
initialization paradigm. That is, providing a single way to initialize a
 type that works exactly the same in all circumstances, which can be=20
used for all types. But because it used {} syntax, it was also adopted=20
into providing a way to initialize an arbitrary object from a sequence=20
of equivalently typed parameters. But that wasn't its primary purpose.<br><=
br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div=
><span style=3D"font-family:courier new,monospace">That is the slogan/promo=
tional phase for the most of materials about C++11.<br>But the initializati=
on of the vector is not uniform with the build-in arrays, which<br>is supri=
sing for the users and make learning of C++ harder, not easer as <br>unifor=
m initialization suppose to. Especially when no presentation/material know =
to me<br>on C++11 mentions this - they use the slogan.<br></span></div></di=
v></blockquote><div>&nbsp;<br>That's because it's fairly minor, all things =
considered. The far more eggregious issue with UI is that initializer_list =
constructors can hide constructors that just so happen to take the same typ=
es of parameters. The fact that you can't put a non-copyable type in a brac=
ed-init-list that will be converted into an initializer_list is pretty mino=
r next to hiding important constructors, thus forcing you back into () cons=
tructor syntax.<br>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"m=
argin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"=
><div dir=3D"ltr"><div><span style=3D"font-family:courier new,monospace"><b=
>Was another approach possible?</b><br>I think yes. To point is to not use =
2-face initialization and use varidatic templates instead:<br></span></div>=
</div></blockquote><div><br>Um, how does that help? It now turns something =
that was quite simple into something incredibly complex. Yes, it solves one=
 problem, but it creates many more.<br><br>It makes accidental narrowing ve=
ry possible. It makes the compiler errors you get for creating a braced-ini=
t-list of different types much more oddball. It causes the generation of lo=
ts of pointless code, bloating compile times needlessly (it's a list of kno=
wn size. We shouldn't have to template metaprogram recurse through it). It =
also conflicts with other parts of uniform initialization: being able to ca=
ll non-initializer_list constructors with braced-init-lists.<i></i> Lastly,=
 there's no way to differentiate between a variadic template intended for s=
ome other purpose and an object that you want to be constructed from an arb=
itrary list of values.<br>&nbsp;</div><blockquote class=3D"gmail_quote" sty=
le=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left=
: 1ex;"><div dir=3D"ltr"><div><span style=3D"font-family:courier new,monosp=
ace"><font face=3D"arial,sans-serif">Of course this code needs allocator su=
pport (std::allocator_arg should be used), but this<br>is doable.<br><br>Th=
is will of course make writing an STL-like container even harder, but the a=
llocator support<br>and exception safety already make this a really hrd tas=
k so that should not be a problem. Also<br>there will be some problem with =
ambiguity of constructor. But from the user perspective the goal will<br>be=
 achived - the vector intialization will be uniform with intialization of b=
uild in arrays, even considering<br>performance.<br></font></span></div></d=
iv></blockquote><div><br>There are a lot more uses for having an object wit=
h an initializer_list constructor than <i>just</i> an STL-compliant contain=
er type. We shouldn't make you have to go through that much effort to proce=
ss <i>an array</i>.</div><br><font face=3D"arial,sans-serif">As people have=
 said, this is a solveable problem. We may need a new "initializer_list" ty=
pe to solve it, but it can certainly be resolved under the existing paradig=
m.</font><br></div>

<p></p>

-- <br />
&nbsp;<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 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_2999_31542940.1376524753480--

.
