220 29090 <34f09dd5-e231-4a0b-a218-48c8eabe73c5@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: m.cencora@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Initializer list for move-only types
Date: Wed, 26 Oct 2016 06:35:25 -0700 (PDT)
Lines: 133
Approved: news@gmane.org
Message-ID: <34f09dd5-e231-4a0b-a218-48c8eabe73c5@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2104_556885896.1477488925721"
X-Trace: blaine.gmane.org 1477488951 26237 195.159.176.226 (26 Oct 2016 13:35:51 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 26 Oct 2016 13:35:51 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD7YFUMJRYMBBH7CYLAAKGQEEXB3WAI@isocpp.org Wed Oct 26 15:35:47 2016
Return-path: <std-proposals+bncBD7YFUMJRYMBBH7CYLAAKGQEEXB3WAI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qt0-f200.google.com ([209.85.216.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD7YFUMJRYMBBH7CYLAAKGQEEXB3WAI@isocpp.org>)
	id 1bzOMa-0004Gz-Dj
	for gclcip-std-proposals@m.gmane.org; Wed, 26 Oct 2016 15:35:28 +0200
Original-Received: by mail-qt0-f200.google.com with SMTP id g32sf2805439qta.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 26 Oct 2016 06:35:31 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=adNaIO2IDBSxiOBjpPrjT42T2S/hLNRZ4rFz2lgnPyc=;
        b=usGO6K40rSCU+alpdhuu57SPYsOUT+XESRDl55YTMf7BA6VP9Zg9FZF/CVLZz89S7H
         xhCL6jqdELYU/EIWw3EnPen2zEvPAXwFIthESTsuUGwDoHpP8loJsxPKvGUkhvB9cDhS
         UOAy0mswVibPVqVIV9ROJ3Gt7mRoD5EpFQG80lsabzdST5peI+Z0es+nAbQxE24EdjAf
         u6BDmFmofGRqe6x1UmKCEKKG+9Xn/wrlhFkzKKZA79I95oEun2gTHVEx3nbyjmBFsxza
         3WcffrAOiRwOSS5AyA0LSBEqfxZ2m3/R9Vcf3BnFXg3PfiDu7PnElbS42Y/x5LaRgh3k
         /OQA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=adNaIO2IDBSxiOBjpPrjT42T2S/hLNRZ4rFz2lgnPyc=;
        b=LCTdjR8lYRW6Fdei+LgZXtkf4FMPflul8WPGK8HE5bFeGFlA0o3Zb+gQrnc7tv8QQU
         5bRZMIljp95xw2iiRTE4mkM2CR1+mFFAWHeBg0VqVHv3c8I+atdmVAQksW4AtyS64F/G
         DFpqocTje88QSKfPh7S1x6mpB2/bXA3qyQAPG1M328Q7wZwPFd+VSBofNirAU1X4i1Ne
         4dN3J0qbwy4+FjhndXwl+OwO2+oYTa7jQI4ttW/QkMIHrQHpbZHDJ7X9wv4O3nh+dNX/
         8MMbclJweTbm/Hfn2bYXA94Zs8w1d65xXW6pxUp7NjO4q4y6125szl+1kL2iXfxw7NTL
         Xeqw==
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:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=adNaIO2IDBSxiOBjpPrjT42T2S/hLNRZ4rFz2lgnPyc=;
        b=Y8bZIjANN1h54k2CCzNY79w6HuJqCyu2n8Mz04QGhsN+aaMzj6cEg3JOpE46jldpHm
         L8NNMra6NvNI/95NRo+V2vegGKVx+L8I0Wyvw5OCzDV1mJLLj9FyS9u/cnyHzhVPRXG3
         qlAcsK/s0dKoOJDRkBnuaNkZkNTrkItDeH8HdwM037H82xsai1yZsDmkmBdrwG7OROA5
         aywFSDcYRnwV/7vgTnasWwjmddNGc2wi44iqLovAR8cSFQc2/ZiB6SCOOfgLrZYsPza5
         NCpYCpm+t4V53UnVHY6w+JFhcutVwBMxbCO2+ko8+eNUGD8knOTzYY+76J3KJ5RTA1Cq
         kNOQ==
X-Gm-Message-State: ABUngvel6X6UJdZldTofiPRgWrX2gpqLwPYPIAoK4WmNPAc06lg6JcbULfRxoUMXhlBTsg==
X-Received: by 10.200.40.189 with SMTP id i58mr509342qti.76.1477488930799;
        Wed, 26 Oct 2016 06:35:30 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.57.142 with SMTP id l136ls1883042ita.20.canary-gmail; Wed,
 26 Oct 2016 06:35:26 -0700 (PDT)
X-Received: by 10.36.53.9 with SMTP id k9mr520677ita.8.1477488926889;
        Wed, 26 Oct 2016 06:35:26 -0700 (PDT)
X-Original-Sender: m.cencora@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:29090
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29090>

------=_Part_2104_556885896.1477488925721
Content-Type: multipart/alternative; 
	boundary="----=_Part_2105_1204335180.1477488925721"

------=_Part_2105_1204335180.1477488925721
Content-Type: text/plain; charset=UTF-8

Hi,

in C++14 we can construct std::array with a list of move-only objects 
(non-copyable) thanks to aggregate initialization.
Unfortunately we cannot do the same for std::vector of move-only types, 
because initializer list points to const objects.
While language experts know the reason of it, from pure user perspective it 
is inconsistent.

#include <iterator>
#include <vector>
#include <array>

struct MoveOnly
{
   MoveOnly(MoveOnly&&) = default;
   MoveOnly& operator=(MoveOnly&&) = default;
};

int main()
{
   // works just fine
   std::array<MoveOnly, 4> arr = {{
      MoveOnly{},
      MoveOnly{},
      MoveOnly{},
      MoveOnly{}
   }};

   // does not compile
   std::vector<MoveOnly> vec = {
      MoveOnly{},
      MoveOnly{},
      MoveOnly{},
      MoveOnly{}
   };

  // workaround
  std::vector<MoveOnly> vec2(std::make_move_iterator(arr.begin()),
                             std::make_move_iterator(arr.end()));
}



Can this be fixed?

Regards,
Maciej

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/34f09dd5-e231-4a0b-a218-48c8eabe73c5%40isocpp.org.

------=_Part_2105_1204335180.1477488925721
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<div><br></div><div>in C++14 we can construct std::arra=
y with a list of move-only objects (non-copyable) thanks to aggregate initi=
alization.</div><div>Unfortunately we cannot do the same for std::vector of=
 move-only types, because initializer list points to const objects.</div><d=
iv>While language experts know the reason of it, from pure user perspective=
 it is inconsistent.</div><div><br></div><div><div class=3D"prettyprint" st=
yle=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgro=
und-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><div class=3D"subprettyprint"><font color=3D"#660066">#inclu=
de &lt;iterator&gt;<br>#include &lt;vector&gt;</font></div><div class=3D"su=
bprettyprint"><font color=3D"#660066">#include &lt;array&gt;</font></div><d=
iv class=3D"subprettyprint"><font color=3D"#660066"><br></font></div><div c=
lass=3D"subprettyprint"><font color=3D"#660066">struct MoveOnly</font></div=
><div class=3D"subprettyprint"><font color=3D"#660066">{</font></div><div c=
lass=3D"subprettyprint"><font color=3D"#660066">=C2=A0 =C2=A0MoveOnly(MoveO=
nly&amp;&amp;) =3D default;</font></div><div class=3D"subprettyprint"><font=
 color=3D"#660066">=C2=A0 =C2=A0MoveOnly&amp; operator=3D(MoveOnly&amp;&amp=
;) =3D default;</font></div><div class=3D"subprettyprint"><font color=3D"#6=
60066">};</font></div><div class=3D"subprettyprint"><font color=3D"#660066"=
><br></font></div><div class=3D"subprettyprint"><font color=3D"#660066">int=
 main()</font></div><div class=3D"subprettyprint"><font color=3D"#660066">{=
<br>=C2=A0 =C2=A0// works just fine</font></div><div class=3D"subprettyprin=
t"><font color=3D"#660066">=C2=A0 =C2=A0std::array&lt;MoveOnly, 4&gt; arr =
=3D {{</font></div><div class=3D"subprettyprint"><font color=3D"#660066">=
=C2=A0 =C2=A0 =C2=A0 MoveOnly{},</font></div><div class=3D"subprettyprint">=
<font color=3D"#660066">=C2=A0 =C2=A0 =C2=A0 MoveOnly{},</font></div><div c=
lass=3D"subprettyprint"><font color=3D"#660066">=C2=A0 =C2=A0 =C2=A0 MoveOn=
ly{},</font></div><div class=3D"subprettyprint"><font color=3D"#660066">=C2=
=A0 =C2=A0 =C2=A0 MoveOnly{}</font></div><div class=3D"subprettyprint"><fon=
t color=3D"#660066">=C2=A0 =C2=A0}};</font></div><div class=3D"subprettypri=
nt"><font color=3D"#660066"><br>=C2=A0 =C2=A0// does not compile</font></di=
v><div class=3D"subprettyprint"><font color=3D"#660066">=C2=A0 =C2=A0std::v=
ector&lt;MoveOnly&gt; vec =3D {</font></div><div class=3D"subprettyprint"><=
font color=3D"#660066">=C2=A0 =C2=A0 =C2=A0 MoveOnly{},</font></div><div cl=
ass=3D"subprettyprint"><font color=3D"#660066">=C2=A0 =C2=A0 =C2=A0 MoveOnl=
y{},</font></div><div class=3D"subprettyprint"><font color=3D"#660066">=C2=
=A0 =C2=A0 =C2=A0 MoveOnly{},</font></div><div class=3D"subprettyprint"><fo=
nt color=3D"#660066">=C2=A0 =C2=A0 =C2=A0 MoveOnly{}</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">=C2=A0 =C2=A0};<br><br>=C2=A0 /=
/ workaround<br><div class=3D"subprettyprint">=C2=A0 std::vector&lt;MoveOnl=
y&gt; vec2(std::make_move_iterator(arr.begin()),</div><div class=3D"subpret=
typrint">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0std::make_move_iterator(arr.end()));<=
/div></font></div><div class=3D"subprettyprint"><font color=3D"#660066">}</=
font></div><div><br></div></div></code></div><br><br></div><div>Can this be=
 fixed?</div><div><br></div><div>Regards,</div><div>Maciej</div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/34f09dd5-e231-4a0b-a218-48c8eabe73c5%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/34f09dd5-e231-4a0b-a218-48c8eabe73c5=
%40isocpp.org</a>.<br />

------=_Part_2105_1204335180.1477488925721--

------=_Part_2104_556885896.1477488925721--

.
