220 18340 <064e1cec-7a5b-4550-b694-6570e1702776@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: Use cases for dyn_array
Date: Mon, 1 Jun 2015 11:03:47 -0700 (PDT)
Lines: 273
Approved: news@gmane.org
Message-ID: <064e1cec-7a5b-4550-b694-6570e1702776@isocpp.org>
References: <a0542458-0240-4644-b313-55e257823db1@isocpp.org>
 <CAFk2RUbREdNuGDaZugxDwG=Ck66LhC4knWTTR-mLGvGktfP5Rg@mail.gmail.com>
 <c6596fb4-ec4b-4263-b60f-ded11e4b9af0@isocpp.org>
 <F2E7E68D-491E-42AB-87A8-975FD55897B7@mac.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3804_982427710.1433181827443"
X-Trace: ger.gmane.org 1433181838 12023 80.91.229.3 (1 Jun 2015 18:03:58 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 1 Jun 2015 18:03:58 +0000 (UTC)
Cc: potswa@mac.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDELF54RTIGRBBF5WKVQKGQEVQYG3XI@isocpp.org Mon Jun 01 20:03:54 2015
Return-path: <std-proposals+bncBDELF54RTIGRBBF5WKVQKGQEVQYG3XI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f197.google.com ([209.85.223.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDELF54RTIGRBBF5WKVQKGQEVQYG3XI@isocpp.org>)
	id 1YzU3y-0004d5-1F
	for gclcip-std-proposals@m.gmane.org; Mon, 01 Jun 2015 20:03:50 +0200
Original-Received: by iecxk8 with SMTP id xk8sf238853426iec.3
        for <gclcip-std-proposals@m.gmane.org>; Mon, 01 Jun 2015 11:03:49 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc: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=LFPkaDd0iOCKYsMX5hmY0RIBkzyKp5kPVxde7fJcaDg=;
        b=X6h/R9rMA4i94A/Rh1IkVaFAL+Y5iL/D0XFlK58zmL7t8H9S8wIrFG1U4tY93yYRpJ
         DsuUpAhR6NVJThAFUB1TLG4Q82S/RTTwOOgCgfSE2w/T5t1ZD0omcvI4tg/ZDl2q5k4O
         W+8PN3oAzu0sbIiGCpRLaeJEUYo7Zabe6Nhp0KKyFyVDpdNC45RXVAFyoDNSkNkp0TZ7
         BQqHD3oLJqTli0YkJEzunWE/CNtPxp6o9UBrVnjXg0Y9B1+dPBKx0YO1bfRn8YMPF2T4
         K3nkxOdCVlkNPrhWS2n2euP1CFStcJ5+EhJTtulUg67OG9cZX3exWlRYSvJJOj5SeGct
         cFfA==
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:cc: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=LFPkaDd0iOCKYsMX5hmY0RIBkzyKp5kPVxde7fJcaDg=;
        b=jPA9DVoIKRPaVATITqU4PxeSpL559jxMhCwn3dMmxhOpiekvQ3Be+hvHXouC6FdYP5
         IgSIH1kebljSnI3FADD/uqXTJOQ5FVsi/cDCwPztITgsXTIKF6IOI35wUOG5qjoOFEw1
         CpJhtZhjgrVdHS6Q3jdAyyxXqy4nBj5FJdnHELyHqcGCMS1LQqNV9LyHg994R1ny+SP9
         nQoqnuPHSgLaZOKxWa5Vk1MdBqkl/xpFXs2GLh9gDkNIsltCbBh48e/y35+spo4Nmw0P
         fXsxRq/sikWtGLOYM4N6joNT52XGu4ux6BGJ1a7syshjaKyefpgkv9dDCrK5Bnb+u2dR
         jp3w==
X-Gm-Message-State: ALoCoQmFcZNSrDbgbQt+w4+83NfTdMi0U+BsCo8S38SjoxUpLtH+w6vD2FjP+0bwkhnPbQjoh6Z6
X-Received: by 10.182.233.230 with SMTP id tz6mr11444487obc.21.1433181828780;
        Mon, 01 Jun 2015 11:03:48 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.91.101 with SMTP id y92ls2794635qgd.43.gmail; Mon, 01 Jun
 2015 11:03:48 -0700 (PDT)
X-Received: by 10.140.20.40 with SMTP id 37mr46024qgi.26.1433181828118;
        Mon, 01 Jun 2015 11:03:48 -0700 (PDT)
In-Reply-To: <F2E7E68D-491E-42AB-87A8-975FD55897B7@mac.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:18340
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/18340>

------=_Part_3804_982427710.1433181827443
Content-Type: multipart/alternative; 
	boundary="----=_Part_3805_1808243834.1433181827443"

------=_Part_3805_1808243834.1433181827443
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Monday, June 1, 2015 at 1:33:34 PM UTC-4, David Krauss wrote:
>
>
> On 2015=E2=80=9306=E2=80=9302, at 1:20 AM, Matthew Fioravante <fmatth...@=
gmail.com=20
> <javascript:>> wrote:
>
> unique_ptr<T[]> has some limitations:
>
> 1) It doesn't store the size of the block, so you need to either keep=20
> track of it separately or write a wrapper type, which is essentially what=
=20
> I'm talking about.
> 2) It only allows you to construct the objects with the default=20
> constructor, which can be very limiting, especially for non-copy/non-move=
=20
> types.
>
>
> Both of these can be solved using a custom allocator.
>

Using a custom allocator to change which constructors are called underneath=
=20
seems like a hack to me. I know its in the standard but using it for=20
something like this feels like a hack.

I don't just want to call a different constructor, I want to call a=20
different constructor with different arguments for each element and=20
possibly different constructors for the elements themselves.

For example if I have this:
struct Foo { Foo(int); Foo(const Foo&) =3D delete; Foo(Foo&&) =3D delete; F=
oo&=20
operator=3D(const Foo&) =3D delete; Foo& operator=3D(Foo&&) =3D delete; };

std::vector<int> ivec =3D /*something*/;

I'd like to be able to construct a fixed_array<Foo> a, where each element=
=20
a[i] is inplace constructed with ivec[i].

If you can do such a thing with a custom allocator, its still very painful=
=20
to write. The standard could potentially provide an allocator template=20
which you could feed a lambda for construction which might help.

Even with all of that, the allocator becomes part of the array container's=
=20
type which is completely unnecessary. We only need the construction logic=
=20
during the construction of fixed_array, after that it can be thrown away.=
=20
Having different allocators only for this logic confuses things because=20
outside of how they were constructed, 2 such fixed_arrays should be of=20
exactly the same type.=20

Also the copy/move constructors may also call Allocator::construct() and=20
this can be problematic unless you carefully add construct() overloads for=
=20
copy/move that don't trigger your lambda.

If construct() is implemented using a lambda/functor which has state (i.e.=
=20
capture variables), now you have to carry around copies of that state=20
forever with your fixed_array. Outside of the constructor for fixed_array,=
=20
this state is never needed again and is likely even invalidated as your=20
fixed_array is passed around to different scopes.

Finally, if such a construction mechanism was added for fixed_array, I=20
would see no reason not to also include it for std::array which has no=20
allocator.

Maybe this whole concept of inplace construction via lambdas/iterators=20
deserves a thread and proposal of its own.


> I've wondered about the omission of std::allocate_unique. Has it ever=20
> come up?
>
> There would need to be a generic allocator-to-deleter adapter, which=20
> should be generally useful and not too difficult. The general case would=
=20
> need to store an element count, because that is expected by=20
> allocator::deallocate. This could be publicly accessible.
>

--=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_3805_1808243834.1433181827443
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, June 1, 2015 at 1:33:34 PM UTC-4, David=
 Krauss wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"wo=
rd-wrap:break-word"><br><div><blockquote type=3D"cite"><div>On 2015=E2=80=
=9306=E2=80=9302, at 1:20 AM, Matthew Fioravante &lt;<a href=3D"javascript:=
" target=3D"_blank" gdf-obfuscated-mailto=3D"BKC4GeOzqBgJ" rel=3D"nofollow"=
 onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.hre=
f=3D'javascript:';return true;">fmatth...@gmail.com</a>&gt; wrote:</div><br=
><div><span style=3D"font-family:Helvetica;font-size:12px;font-style:normal=
;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:n=
ormal;text-align:start;text-indent:0px;text-transform:none;white-space:norm=
al;word-spacing:0px;float:none;display:inline!important">unique_ptr&lt;T[]&=
gt; has some limitations:</span><br style=3D"font-family:Helvetica;font-siz=
e:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spac=
ing:normal;line-height:normal;text-align:start;text-indent:0px;text-transfo=
rm:none;white-space:normal;word-spacing:0px"><br style=3D"font-family:Helve=
tica;font-size:12px;font-style:normal;font-variant:normal;font-weight:norma=
l;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px=
;text-transform:none;white-space:normal;word-spacing:0px"><span style=3D"fo=
nt-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;fo=
nt-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;=
text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;flo=
at:none;display:inline!important">1) It doesn't store the size of the block=
, so you need to either keep track of it separately or write a wrapper type=
, which is essentially what I'm talking about.</span><br style=3D"font-fami=
ly:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weig=
ht:normal;letter-spacing:normal;line-height:normal;text-align:start;text-in=
dent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span sty=
le=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant:n=
ormal;font-weight:normal;letter-spacing:normal;line-height:normal;text-alig=
n:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing=
:0px;float:none;display:inline!important">2) It only allows you to construc=
t the objects with the default constructor, which can be very limiting, esp=
ecially for non-copy/non-move types.</span><br></div></blockquote></div><br=
><div>Both of these can be solved using a custom allocator.</div></div></bl=
ockquote><div><br>Using a custom allocator to change which constructors are=
 called underneath seems like a hack to me. I know its in the standard but =
using it for something like this feels like a hack.<br><br>I don't just wan=
t to call a different constructor, I want to call a different constructor w=
ith different arguments for each element and possibly different constructor=
s for the elements themselves.<br><br>For example if I have this:<br><div c=
lass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-=
color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wra=
p: 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"> </span><span style=3D=
"color: #606;" class=3D"styled-by-prettify">Foo</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"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Foo</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"sty=
led-by-prettify">Foo</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&amp;)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">delete</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: #6=
06;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Foo</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&amp;&amp;)</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">delete</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">operator</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D(</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;)</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </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=
: #008;" class=3D"styled-by-prettify">delete</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: #606;" class=3D"styl=
ed-by-prettify">Foo</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">opera=
tor</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D(</s=
pan><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;)</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">delete</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br><br>std</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">vector=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ivec </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">/*something*/</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br>=
I'd like to be able to construct a fixed_array&lt;Foo&gt; a, where each ele=
ment a[i] is inplace constructed with ivec[i].<br><br>If you can do such a =
thing with a custom allocator, its still very painful to write. The standar=
d could potentially provide an allocator template which you could feed a la=
mbda for construction which might help.<br><br>Even with all of that, the a=
llocator becomes part of the array container's type which is completely unn=
ecessary. We only need the construction logic during the construction of fi=
xed_array, after that it can be thrown away. <br>Having different allocator=
s only for this logic confuses things because outside of how they were cons=
tructed, 2 such fixed_arrays should be of exactly the same type. <br><br>Al=
so the copy/move constructors may also call Allocator::construct() and this=
 can be problematic unless you carefully add construct() overloads for copy=
/move that don't trigger your lambda.<br><br>If construct() is implemented =
using a lambda/functor which has state (i.e. capture variables), now you ha=
ve to carry around copies of that state forever with your fixed_array. Outs=
ide of the constructor for fixed_array, this state is never needed again an=
d is likely even invalidated as your fixed_array is passed around to differ=
ent scopes.<br><br>Finally, if such a construction mechanism was added for =
fixed_array, I would see no reason not to also include it for std::array wh=
ich has no allocator.<br><br>Maybe this whole concept of inplace constructi=
on via lambdas/iterators deserves a thread and proposal of its own.<br><br>=
</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:=
break-word"><div><br></div><div>I've wondered about the omission of <font f=
ace=3D"Courier">std::allocate_unique</font>. Has it ever come up?</div><div=
><br></div><div>There would need to be a generic allocator-to-deleter adapt=
er, which should be generally useful and not too difficult. The general cas=
e would need to store an element count, because that is expected by <font f=
ace=3D"Courier">allocator::deallocate</font>. This could be publicly access=
ible.</div></div></blockquote></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_3805_1808243834.1433181827443--
------=_Part_3804_982427710.1433181827443--

.
