Topic: Use cases for dyn_array
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 1 Jun 2015 09:07:14 -0700 (PDT)
Raw View
------=_Part_696_1083301539.1433174834781
Content-Type: multipart/alternative;
boundary="----=_Part_697_713282275.1433174834787"
------=_Part_697_713282275.1433174834787
Content-Type: text/plain; charset=UTF-8
I know dyn_array was removed from the standard for now, but I have some
uses cases for a type like this. Specifically for a fixed size heap
allocated array. I don't much care whether or not its optimized to use
stack memory.
Specifically, a fixed size heap allocated array gives you the following
capabilities that std::vector does not. Note that these may or may not be
possible with the latest specification of dyn_array.
1) You can store a collection of non-copyable / non-movable types in a
contiguous memory block, improving cache locality.
2) You can store const objects. This allows you to construct once and then
enforce invariants that the objects are never modified forever after.
3) The container will always perform an exact size memory allocation for
you, unlike vector which may allocate more in anticipation of future
push_back() calls.
4) The container only needs to store 2 pointers instead of 3, making
objects of this type much more cache line friendly.
One issue that comes up when you're trying to do (1) is how to construct
the objects in place. Since the type is not movable, you have to construct
the uninitialized memory directly using placement new. I came up with this
kind of constructor. Some improvements could be made to the interface, but
this is the general idea of how such a thing would work.
template <typename F, typename... Iters>
dyn_array(size_t sz, F&& f, Iters... iters);
using T = /*some type*/
auto make_fn = [](T* uninitialized_obj, auto& iter0, auto& iter1) {
new (uninitialized_obj) T(*iter0, *iter1);
};
assert(some_container0.size() >= 10);
assert(some_container1.suze() >= 10);
auto a = dyn_array<T>(10, make_fn, some_container0.begin(), some_container1.
begin());
For (2), sometimes you might want to first allocate the objects as
non-const into a temporary and finally move them into their final const
destination when you are done setting them up
struct Foo {
dyn_array<const T> dat;
Foo(int sz) {
auto a = DynArray<T>(sz);
for(auto& t: a) {
modify(t);
}
dat = std::move(a);
}
};
For this to work, first dyn_array<const T> should be move constructible
from dyn_array<T>. The move constructor should also be implemented to just
steal the pointer and leave the moved from object in a default constructed
state, instead of moving the elements. This means that a dyn_array
constructed with a size and moved from will have a different size
thereafter, but this is not different then overwriting an existing array
with copy assignment.
--
---
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_697_713282275.1433174834787
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I know dyn_array was removed from the standard for now, bu=
t I have some uses cases for a type like this. Specifically for a fixed siz=
e heap allocated array. I don't much care whether or not its optimized to u=
se stack memory.<br><br>Specifically, a fixed size heap allocated array giv=
es you the following capabilities that std::vector does not. Note that thes=
e may or may not be possible with the latest specification of dyn_array.<br=
><br>1) You can store a collection of non-copyable / non-movable types in a=
contiguous memory block, improving cache locality.<br>2) You can store con=
st objects. This allows you to construct once and then enforce invariants t=
hat the objects are never modified forever after.<br>3) The container will =
always perform an exact size memory allocation for you, unlike vector which=
may allocate more in anticipation of future push_back() calls.<br>4) The c=
ontainer only needs to store 2 pointers instead of 3, making objects of thi=
s type much more cache line friendly.<br><br>One issue that comes up when y=
ou're trying to do (1) is how to construct the objects in place. Since the =
type is not movable, you have to construct the uninitialized memory directl=
y using placement new. I came up with this kind of constructor. Some improv=
ements could be made to the interface, but this is the general idea of how =
such a thing would work.<br><br><div class=3D"prettyprint" style=3D"backgro=
und-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-sty=
le: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pretty=
print"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"=
styled-by-prettify">template</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: #008;" class=3D"styled-by-prettif=
y">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> F</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: #008;" class=3D"styled-by-prettify">typename</span><span styl=
e=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: #606=
;" class=3D"styled-by-prettify">Iters</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>dyn_array</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">size_t sz</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> F</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f<=
/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: #606;" class=3D"styled-by-prettify">Iters</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> iters</span><span style=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: #008;" class=
=3D"styled-by-prettify">using</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> T </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/*so=
me type*/</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> make_fn </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">[](</span><span style=3D"col=
or: #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"> uninitialized_obj</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: #008;" class=3D"style=
d-by-prettify">auto</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> iter0</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: #008;" class=3D"styled-by-prettify">auto</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> iter1</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=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"sty=
led-by-prettify">new</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">uninitia=
lized_obj</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"styled-by-prettify">(*</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">iter0</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: #660;" cla=
ss=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">iter1</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=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: #008;" class=3D"styled-by-prettify">assert</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">some_container0</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">size</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #00=
0;" 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: #066;" class=3D"styled-b=
y-prettify">10</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">assert</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">some_container1</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">suze</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">>=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">10</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> a </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> dyn_array</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">>(</span><span style=3D"color: #066;" c=
lass=3D"styled-by-prettify">10</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> make_fn</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
some_container0</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">.</span><span style=3D"color: #008;" class=3D"styled-by-prettify">beg=
in</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(),</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> some_container=
1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">begin</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">());</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v><br>For (2), sometimes you might want to first allocate the objects as no=
n-const into a temporary and finally move them into their final const desti=
nation when you are done setting them up<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=
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"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> dyn_array</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">const</span><span 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"> dat</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: #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">int</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> sz</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </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: #008;" class=3D"styled-by-prettify">au=
to</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a </spa=
n><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: #606;" class=3D"styled-by-prettify">DynArray</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">>(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">sz</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">for</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</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;" class=3D"styled-by-prettify"> t</span><s=
pan 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"colo=
r: #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: #000;" class=3D"styled-b=
y-prettify"><br> modify</span><span style=3D"color: #66=
0;" 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-pre=
ttify"><br> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br> dat </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">mov=
e</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 styl=
e=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></div></code></div><br>For this to work, first=
dyn_array<const T> should be move constructible from dyn_array<T&=
gt;. The move constructor should also be implemented to just steal the poin=
ter and leave the moved from object in a default constructed state, instead=
of moving the elements. This means that a dyn_array constructed with a siz=
e and moved from will have a different size thereafter, but this is not dif=
ferent then overwriting an existing array with copy assignment.<br><br></di=
v>
<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_697_713282275.1433174834787--
------=_Part_696_1083301539.1433174834781--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Mon, 1 Jun 2015 19:13:26 +0300
Raw View
On 1 June 2015 at 19:07, Matthew Fioravante <fmatthew5876@gmail.com> wrote:
> I know dyn_array was removed from the standard for now, but I have some uses
> cases for a type like this. Specifically for a fixed size heap allocated
> array. I don't much care whether or not its optimized to use stack memory.
Then it's not dyn_array that you want.
>
> Specifically, a fixed size heap allocated array gives you the following
> capabilities that std::vector does not. Note that these may or may not be
> possible with the latest specification of dyn_array.
>
> 1) You can store a collection of non-copyable / non-movable types in a
> contiguous memory block, improving cache locality.
> 2) You can store const objects. This allows you to construct once and then
> enforce invariants that the objects are never modified forever after.
> 3) The container will always perform an exact size memory allocation for
> you, unlike vector which may allocate more in anticipation of future
> push_back() calls.
> 4) The container only needs to store 2 pointers instead of 3, making objects
> of this type much more cache line friendly.
Any particular reason why you don't just use the array version of unique_ptr?
> For this to work, first dyn_array<const T> should be move constructible from
> dyn_array<T>. The move constructor should also be implemented to just steal
...especially since unique_ptr for array types gives you this.
--
---
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, 1 Jun 2015 10:20:28 -0700 (PDT)
Raw View
------=_Part_3755_1945997168.1433179228719
Content-Type: multipart/alternative;
boundary="----=_Part_3756_198458766.1433179228719"
------=_Part_3756_198458766.1433179228719
Content-Type: text/plain; charset=UTF-8
On Monday, June 1, 2015 at 12:13:28 PM UTC-4, Ville Voutilainen wrote:
>
> On 1 June 2015 at 19:07, Matthew Fioravante <fmatth...@gmail.com
> <javascript:>> wrote:
> > I know dyn_array was removed from the standard for now, but I have some
> uses
> > cases for a type like this. Specifically for a fixed size heap allocated
> > array. I don't much care whether or not its optimized to use stack
> memory.
>
> Then it's not dyn_array that you want.
>
> >
> > Specifically, a fixed size heap allocated array gives you the following
> > capabilities that std::vector does not. Note that these may or may not
> be
> > possible with the latest specification of dyn_array.
> >
> > 1) You can store a collection of non-copyable / non-movable types in a
> > contiguous memory block, improving cache locality.
> > 2) You can store const objects. This allows you to construct once and
> then
> > enforce invariants that the objects are never modified forever after.
> > 3) The container will always perform an exact size memory allocation for
> > you, unlike vector which may allocate more in anticipation of future
> > push_back() calls.
> > 4) The container only needs to store 2 pointers instead of 3, making
> objects
> > of this type much more cache line friendly.
>
> Any particular reason why you don't just use the array version of
> unique_ptr?
>
unique_ptr<T[]> has some limitations:
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.
2) It only allows you to construct the objects with the default
constructor, which can be very limiting, especially for non-copy/non-move
types.
>
> > For this to work, first dyn_array<const T> should be move constructible
> from
> > dyn_array<T>. The move constructor should also be implemented to just
> steal
>
> ..especially since unique_ptr for array types gives you this.
>
--
---
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_3756_198458766.1433179228719
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, June 1, 2015 at 12:13:28 PM UTC-4, Vill=
e Voutilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 1 June =
2015 at 19:07, Matthew Fioravante <<a href=3D"javascript:" target=3D"_bl=
ank" gdf-obfuscated-mailto=3D"Kqw1Xy6U110J" rel=3D"nofollow" onmousedown=3D=
"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript=
:';return true;">fmatth...@gmail.com</a>> wrote:
<br>> I know dyn_array was removed from the standard for now, but I have=
some uses
<br>> cases for a type like this. Specifically for a fixed size heap all=
ocated
<br>> array. I don't much care whether or not its optimized to use stack=
memory.
<br>
<br>Then it's not dyn_array that you want.
<br>
<br>>
<br>> Specifically, a fixed size heap allocated array gives you the foll=
owing
<br>> capabilities that std::vector does not. Note that these may or may=
not be
<br>> possible with the latest specification of dyn_array.
<br>>
<br>> 1) You can store a collection of non-copyable / non-movable types =
in a
<br>> contiguous memory block, improving cache locality.
<br>> 2) You can store const objects. This allows you to construct once =
and then
<br>> enforce invariants that the objects are never modified forever aft=
er.
<br>> 3) The container will always perform an exact size memory allocati=
on for
<br>> you, unlike vector which may allocate more in anticipation of futu=
re
<br>> push_back() calls.
<br>> 4) The container only needs to store 2 pointers instead of 3, maki=
ng objects
<br>> of this type much more cache line friendly.
<br>
<br>Any particular reason why you don't just use the array version of uniqu=
e_ptr?
<br></blockquote><div><br>unique_ptr<T[]> has some limitations:<br><b=
r>1) It doesn't store the size of the block, so you need to either keep tra=
ck of it separately or write a wrapper type, which is essentially what I'm =
talking about.<br>2) It only allows you to construct the objects with the d=
efault constructor, which can be very limiting, especially for non-copy/non=
-move types.<br> </div><blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>> For this to work, first dyn_array<const T> should be move co=
nstructible from
<br>> dyn_array<T>. The move constructor should also be implemente=
d to just steal
<br>
<br>..especially since unique_ptr for array types gives you this.
<br></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" 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_3756_198458766.1433179228719--
------=_Part_3755_1945997168.1433179228719--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Mon, 1 Jun 2015 20:28:20 +0300
Raw View
On 1 June 2015 at 20:20, Matthew Fioravante <fmatthew5876@gmail.com> wrote:
>> Any particular reason why you don't just use the array version of
>> unique_ptr?
> unique_ptr<T[]> has some limitations:
> 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.
> 2) It only allows you to construct the objects with the default constructor,
> which can be very limiting, especially for non-copy/non-move types.
The first bit of (2) is not correct, but non-copy types don't work
with an initializer
list, so using them with any sort of array that needs to be
initialized is indeed not possible,
you would need an emplace. It seems to me that such a type should be
prefixed with fixed_,
not with dyn_.
--
---
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: David Krauss <potswa@mac.com>
Date: Tue, 02 Jun 2015 01:33:09 +0800
Raw View
--Apple-Mail=_F2B9B983-B131-4BAA-96B1-410AC3130190
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9306=E2=80=9302, at 1:20 AM, Matthew Fioravante <fmatthew58=
76@gmail.com> wrote:
>=20
> unique_ptr<T[]> has some limitations:
>=20
> 1) It doesn't store the size of the block, so you need to either keep tra=
ck of it separately or write a wrapper type, which is essentially what I'm =
talking about.
> 2) It only allows you to construct the objects with the default construct=
or, which can be very limiting, especially for non-copy/non-move types.
Both of these can be solved using a custom allocator.
I've wondered about the omission of std::allocate_unique. Has it ever come =
up?
There would need to be a generic allocator-to-deleter adapter, which should=
be generally useful and not too difficult. The general case would need to =
store an element count, because that is expected by 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/.
--Apple-Mail=_F2B9B983-B131-4BAA-96B1-410AC3130190
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9306=
=E2=80=9302, at 1:20 AM, Matthew Fioravante <<a href=3D"mailto:fmatthew5=
876@gmail.com" class=3D"">fmatthew5876@gmail.com</a>> wrote:</div><br cl=
ass=3D"Apple-interchange-newline"><div class=3D""><span style=3D"font-famil=
y: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; fo=
nt-weight: normal; letter-spacing: normal; line-height: normal; orphans: au=
to; text-align: start; text-indent: 0px; text-transform: none; white-space:=
normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; f=
loat: none; display: inline !important;" class=3D"">unique_ptr<T[]> h=
as some limitations:</span><br style=3D"font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant: normal; font-weight: normal; letter=
-spacing: normal; line-height: normal; orphans: auto; text-align: start; te=
xt-indent: 0px; text-transform: none; white-space: normal; widows: auto; wo=
rd-spacing: 0px; -webkit-text-stroke-width: 0px;" class=3D""><br style=3D"f=
ont-family: Helvetica; font-size: 12px; font-style: normal; font-variant: n=
ormal; font-weight: normal; letter-spacing: normal; line-height: normal; or=
phans: auto; text-align: start; text-indent: 0px; text-transform: none; whi=
te-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-widt=
h: 0px;" class=3D""><span style=3D"font-family: Helvetica; font-size: 12px;=
font-style: normal; font-variant: normal; font-weight: normal; letter-spac=
ing: normal; line-height: normal; orphans: auto; text-align: start; text-in=
dent: 0px; text-transform: none; white-space: normal; widows: auto; word-sp=
acing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !i=
mportant;" class=3D"">1) It doesn't store the size of the block, so you nee=
d to either keep track of it separately or write a wrapper type, which is e=
ssentially what I'm talking about.</span><br style=3D"font-family: Helvetic=
a; font-size: 12px; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; orphans: auto; text-al=
ign: start; text-indent: 0px; text-transform: none; white-space: normal; wi=
dows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=3D"">=
<span style=3D"font-family: Helvetica; font-size: 12px; font-style: normal;=
font-variant: normal; font-weight: normal; letter-spacing: normal; line-he=
ight: normal; orphans: auto; text-align: start; text-indent: 0px; text-tran=
sform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-=
text-stroke-width: 0px; float: none; display: inline !important;" class=3D"=
">2) It only allows you to construct the objects with the default construct=
or, which can be very limiting, especially for non-copy/non-move types.</sp=
an><br class=3D""></div></blockquote></div><br class=3D""><div class=3D"">B=
oth of these can be solved using a custom allocator.</div><div class=3D""><=
br class=3D""></div><div class=3D"">I've wondered about the omission of <fo=
nt face=3D"Courier" class=3D"">std::allocate_unique</font>. Has it ever com=
e up?</div><div class=3D""><br class=3D""></div><div class=3D"">There would=
need to be a generic allocator-to-deleter adapter, which should be general=
ly useful and not too difficult. The general case would need to store an el=
ement count, because that is expected by <font face=3D"Courier" class=3D"">=
allocator::deallocate</font>. This could be publicly accessible.</div></bod=
y></html>
<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 />
--Apple-Mail=_F2B9B983-B131-4BAA-96B1-410AC3130190--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 1 Jun 2015 11:03:47 -0700 (PDT)
Raw View
------=_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 <<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>> 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<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">&)</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">&&)</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">&</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">&)</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">&</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">&&)</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"><int>=
;</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<Foo> 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" 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--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 1 Jun 2015 11:12:44 -0700 (PDT)
Raw View
------=_Part_879_708165819.1433182364723
Content-Type: multipart/alternative;
boundary="----=_Part_880_788548259.1433182364723"
------=_Part_880_788548259.1433182364723
Content-Type: text/plain; charset=UTF-8
Also unique_ptr<T[]> does not have any builtin copy semantics.
If you want create a fixed_array of copyable types, you'll again need to
wrap your unique_ptr in a type.
Honestly, unique_ptr<T[]> seems to be of limited use (maybe only to build a
higher level abstraction). If I want an array of T, then I'd rather have a
complete type that reresents that concept and has all of the member
functions, operators, and semantics expected of an array value type. I'd
want copy/move constructors so I can make that array a data member of a
larger type and take advantage of the rule of zero.
unique_ptr with some wierd custom allocator to store the size and possibly
do construction is not a replacement for a regular array type. Its a hack
that only expert C++ programmers would think to use and be able to rapidly
understand.
--
---
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_880_788548259.1433182364723
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Also unique_ptr<T[]> does not have any builtin copy =
semantics.<br><br>If you want create a fixed_array of copyable types, you'l=
l again need to wrap your unique_ptr in a type.<br><br>Honestly, unique_ptr=
<T[]> seems to be of limited use (maybe only to build a higher level =
abstraction). If I want an array of T, then I'd rather have a complete type=
that reresents that concept and has all of the member functions, operators=
, and semantics expected of an array value type. I'd want copy/move constru=
ctors so I can make that array a data member of a larger type and take adva=
ntage of the rule of zero.<br><br>unique_ptr with some wierd custom allocat=
or to store the size and possibly do construction is not a replacement for =
a regular array type. Its a hack that only expert C++ programmers would thi=
nk to use and be able to rapidly understand.<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_880_788548259.1433182364723--
------=_Part_879_708165819.1433182364723--
.
Author: David Krauss <potswa@mac.com>
Date: Tue, 02 Jun 2015 03:20:18 +0800
Raw View
--Apple-Mail=_ED6DF471-1191-446E-933C-AF88D51F8AAE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9306=E2=80=9302, at 2:12 AM, Matthew Fioravante <fmatthew58=
76@gmail.com> wrote:
>=20
> Also unique_ptr<T[]> does not have any builtin copy semantics.
I don=E2=80=99t think dyn_array is ever likely to support copying, either. =
(It=E2=80=99s way past my bedtime so maybe I shouldn=E2=80=99t bet against =
that having been proposed at some point.)
It sounds like what you really want is a non-resizable version of std::vect=
or, with a std::piecewise_construct constructor.
> If you want create a fixed_array of copyable types, you'll again need to =
wrap your unique_ptr in a type.
>=20
> Honestly, unique_ptr<T[]> seems to be of limited use (maybe only to build=
a higher level abstraction). If I want an array of T, then I'd rather have=
a complete type that reresents that concept and has all of the member func=
tions, operators, and semantics expected of an array value type. I'd want c=
opy/move constructors so I can make that array a data member of a larger ty=
pe and take advantage of the rule of zero.
>=20
> unique_ptr with some wierd custom allocator to store the size and possibl=
y do construction is not a replacement for a regular array type. Its a hack=
that only expert C++ programmers would think to use and be able to rapidly=
understand.
Any solution is easier to use once it=E2=80=99s encapsulated.
template< typename elem >
struct delete_n {
std::size_t size;
void operator () ( elem * p, bool deallocate =3D true ) {
for ( std::reverse_iterator< elem * > b =3D p + size, e =3D p;
b !=3D e; ++ b ) {
b->elem::~elem();
}
if ( deallocate ) ::operator delete( p );
}
};
template< typename elem, typename ... arg, std::size_t ... index >
void forward_init_array( std::index_sequence< index ... >, elem * p, std::s=
ize_t & count, arg && ... a ) {
char x[] { [&] {
new( p + count ) elem( std::forward< arg >( a ) );
++ count; // This is the exception-safe magic: alias the deleter st=
ate.
return =E2=80=98x=E2=80=99;
} () ... };
}
template< typename elem >
class copyable_array
: std::unique_ptr< elem[], delete_n< elem > > {
using typename copyable_array::unique_ptr;
public:
using unique_ptr::operator [];
std::size_t size() const { return this->get_deleter().n; }
template< typename ... arg >
copyable_array( arg ... a )
: unique_ptr( ::operator new( sizeof ... (a) * sizeof (elem) ), { 0=
/* delete_n::n */ } )
{
forward_init_array( std::make_index_sequence< sizeof ... (a) >{}, t=
his->get(), this->get_deleter().n,
std::forward< arg >( a ) ... );
}
copyable_array( copyable_array const & o )
: unique_ptr( ::operator new( o.get_deleter().n * sizeof (elem) ), =
{ 0 } ) {
for ( ; get_deleter().n !=3D o.get_deleter().n; ++ get_deleter().n =
) {
new( this->get() + get_deleter().n ) elem( o[ get_deleter().n ]=
);
}
}
};
Not tested. Sorry for the ugly code. It=E2=80=99s past my bedtime. But, poi=
nt is, there is certainly a library solution for this problem. Tricky as it=
may be, it=E2=80=99s still easier to write than a working and politically-=
correct dynarray implementation.
--=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/.
--Apple-Mail=_ED6DF471-1191-446E-933C-AF88D51F8AAE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9306=
=E2=80=9302, at 2:12 AM, Matthew Fioravante <<a href=3D"mailto:fmatthew5=
876@gmail.com" class=3D"">fmatthew5876@gmail.com</a>> wrote:</div><br cl=
ass=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" class=3D=
"">Also unique_ptr<T[]> does not have any builtin copy semantics.<br =
class=3D""></div></div></blockquote><div><br class=3D""></div><div>I don=E2=
=80=99t think <font face=3D"Courier" class=3D"">dyn_array</font> is ever li=
kely to support copying, either. (It=E2=80=99s way past my bedtime so maybe=
I shouldn=E2=80=99t bet against that having been proposed at some point.)<=
/div><div><br class=3D""></div><div>It sounds like what you really want is =
a non-resizable version of <font face=3D"Courier" class=3D"">std::vector</f=
ont>, with a <font face=3D"Courier" class=3D"">std::piecewise_construct</fo=
nt> constructor.</div><br class=3D""><blockquote type=3D"cite" class=3D""><=
div class=3D""><div dir=3D"ltr" class=3D"">If you want create a fixed_array=
of copyable types, you'll again need to wrap your unique_ptr in a type.<br=
class=3D""><br class=3D"">Honestly, unique_ptr<T[]> seems to be of l=
imited use (maybe only to build a higher level abstraction). If I want an a=
rray of T, then I'd rather have a complete type that reresents that concept=
and has all of the member functions, operators, and semantics expected of =
an array value type. I'd want copy/move constructors so I can make that arr=
ay a data member of a larger type and take advantage of the rule of zero.<b=
r class=3D""><br class=3D"">unique_ptr with some wierd custom allocator to =
store the size and possibly do construction is not a replacement for a regu=
lar array type. Its a hack that only expert C++ programmers would think to =
use and be able to rapidly understand.<br class=3D""></div></div></blockquo=
te><br class=3D""></div><div>Any solution is easier to use once it=E2=80=99=
s encapsulated.</div><div><br class=3D""></div><div><font face=3D"Courier" =
class=3D"">template< typename elem ></font></div><div><font face=3D"C=
ourier" class=3D"">struct delete_n {</font></div><div><font face=3D"Courier=
" class=3D""> std::size_t size;</font></div><div><font face=3D=
"Courier" class=3D""> void operator () ( elem * p, bool deallo=
cate =3D true ) {</font></div><div><font face=3D"Courier" class=3D""> =
for ( std::reverse_iterator< elem * > b =3D p +=
size, e =3D p;</font></div><div><font face=3D"Courier" class=3D""> &=
nbsp; b !=3D e; ++ b ) {</font></div><div><font=
face=3D"Courier" class=3D""> b-&g=
t;elem::~elem();</font></div><div><font face=3D"Courier" class=3D""> =
}</font></div><div><font face=3D"Courier" class=3D"">&=
nbsp; if ( deallocate ) ::operator delete( p );</font>=
</div><div><font face=3D"Courier" class=3D""> }</font></div><d=
iv><font face=3D"Courier" class=3D"">};</font></div><div><font face=3D"Cour=
ier" class=3D""><br class=3D""></font></div><div><font face=3D"Courier" cla=
ss=3D"">template< typename elem, typename ... arg, std::size_t ... index=
></font></div><div><font face=3D"Courier" class=3D"">void forward_init_=
array( std::index_sequence< index ... >, elem * p, std::size_t & =
count, arg && ... a ) {</font></div><div><span style=3D"font-family=
: Courier;" class=3D""> char x[] { [&] {</span></div><div>=
<font face=3D"Courier" class=3D""> new( p + coun=
t ) elem( std::forward< arg >( a ) );</font></div><div><font face=3D"=
Courier" class=3D""> ++ count; // This is the ex=
ception-safe magic: alias the deleter state.</font></div><div><span style=
=3D"font-family: Courier;" class=3D""> return =
=E2=80=98x=E2=80=99;</span></div><div><font face=3D"Courier" class=3D"">&nb=
sp; } () ... };</font></div><div><span style=3D"font-family: Courier=
;" class=3D"">}</span></div><div><font face=3D"Courier" class=3D""><br clas=
s=3D""></font></div><div><font face=3D"Courier" class=3D"">template< typ=
ename elem ></font></div><div><font face=3D"Courier" class=3D"">class co=
pyable_array</font></div><div><font face=3D"Courier" class=3D""> &nbs=
p; : std::unique_ptr< elem[], delete_n< elem > > {</font></div>=
<div><font face=3D"Courier" class=3D""> using typename co=
pyable_array::unique_ptr;</font></div><div><font face=3D"Courier" class=3D"=
">public:</font></div><div><font face=3D"Courier" class=3D""> =
using unique_ptr::operator [];</font></div><div><font face=3D"Courier"=
class=3D""> std::size_t size() const { return this->get_de=
leter().n; }</font></div><div><font face=3D"Courier" class=3D""><br class=
=3D""></font></div><div><font face=3D"Courier" class=3D""> tem=
plate< typename ... arg ></font></div><div><font face=3D"Courier" cla=
ss=3D""> copyable_array( arg ... a )</font></div><div><font fa=
ce=3D"Courier" class=3D""> : unique_ptr( ::opera=
tor new( sizeof ... (a) * sizeof (elem) ), { 0 /* delete_n::n */ } )</font>=
</div><div><font face=3D"Courier" class=3D""> {</font></div><d=
iv><font face=3D"Courier" class=3D""> forward_in=
it_array( std::make_index_sequence< sizeof ... (a) >{}, this->get(=
), this->get_deleter().n,</font></div><div><font face=3D"Courier" class=
=3D""> =
std::forward< arg >( a ) ... );</font></=
div><div><font face=3D"Courier" class=3D""> }</font></div><div=
><font face=3D"Courier" class=3D""><br class=3D""></font></div><div><font f=
ace=3D"Courier" class=3D""> copyable_array( copyable=
_array const & o )</font></div><div><font face=3D"Courier" class=
=3D""> : unique_ptr( ::operator new( o.get_delet=
er().n * sizeof (elem) ), { 0 } ) {</font></div><div><font face=3D"Courier"=
class=3D""> for ( ; get_deleter().n !=3D o.get_=
deleter().n; ++ get_deleter().n ) {</font></div><div><font face=3D"Courier"=
class=3D""> new( this->get() +=
</font><span style=3D"font-family: Courier;" class=3D"">get_deleter()=
..n</span><font face=3D"Courier" class=3D""> ) elem( o[ </font><sp=
an style=3D"font-family: Courier;" class=3D"">get_deleter().n</span><font f=
ace=3D"Courier" class=3D""> ] );</font></div><div><font face=3D"Courie=
r" class=3D""> }</font></div><div><font face=3D"=
Courier" class=3D""> }</font></div><div><font face=3D"Courier"=
class=3D"">};</font></div><div><br class=3D""></div><div>Not tested. Sorry=
for the ugly code. It=E2=80=99s past my bedtime. But, point is, there is c=
ertainly a library solution for this problem. Tricky as it may be, it=E2=80=
=99s still easier to write than a working and politically-correct dynarray =
implementation.</div></body></html>
<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 />
--Apple-Mail=_ED6DF471-1191-446E-933C-AF88D51F8AAE--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 1 Jun 2015 15:40:08 -0700 (PDT)
Raw View
------=_Part_1098_1910036479.1433198408488
Content-Type: multipart/alternative;
boundary="----=_Part_1099_1397547197.1433198408488"
------=_Part_1099_1397547197.1433198408488
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Monday, June 1, 2015 at 3:20:47 PM UTC-4, David Krauss wrote:
>
>
> On 2015=E2=80=9306=E2=80=9302, at 2:12 AM, Matthew Fioravante <fmatth...@=
gmail.com=20
> <javascript:>> wrote:
>
> Also unique_ptr<T[]> does not have any builtin copy semantics.
>
>
> I don=E2=80=99t think dyn_array is ever likely to support copying, either=
.. (It=E2=80=99s=20
> way past my bedtime so maybe I shouldn=E2=80=99t bet against that having =
been=20
> proposed at some point.)
>
> It sounds like what you really want is a non-resizable version of=20
> std::vector, with a std::piecewise_construct constructor.
>
It seems to me that, with N4416=20
<http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4416.pdf> (PDF),=
=20
you'd basically have that: a way to know exactly how much memory=20
std::vector allocated, rather than hoping that vector::reserve didn't=20
over-allocate.
--=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_1099_1397547197.1433198408488
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, June 1, 2015 at 3:20:47 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 2:12 AM, Matthew Fioravante <<a href=3D"javascript:=
" target=3D"_blank" gdf-obfuscated-mailto=3D"SDprw4w5LYEJ" rel=3D"nofollow"=
onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.hre=
f=3D'javascript:';return true;">fmatth...@gmail.com</a>> wrote:</div><br=
><div><div dir=3D"ltr">Also unique_ptr<T[]> does not have any builtin=
copy semantics.<br></div></div></blockquote><div><br></div><div>I don=E2=
=80=99t think <font face=3D"Courier">dyn_array</font> is ever likely to sup=
port copying, either. (It=E2=80=99s way past my bedtime so maybe I shouldn=
=E2=80=99t bet against that having been proposed at some point.)</div><div>=
<br></div><div>It sounds like what you really want is a non-resizable versi=
on of <font face=3D"Courier">std::vector</font>, with a <font face=3D"Couri=
er">std::piecewise_construct</font> constructor.</div></div></div></blockqu=
ote><div><br>It seems to me that, with <a href=3D"http://www.open-std.org/J=
TC1/SC22/WG21/docs/papers/2015/n4416.pdf">N4416</a> (PDF), you'd basically =
have that: a way to know exactly how much memory std::vector allocated, rat=
her than hoping that vector::reserve didn't over-allocate.</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_1099_1397547197.1433198408488--
------=_Part_1098_1910036479.1433198408488--
.
Author: Nevin Liber <nliber@gmail.com>
Date: Mon, 1 Jun 2015 17:55:48 -0500
Raw View
--001a11c3393a17011d05177cba5d
Content-Type: text/plain; charset=UTF-8
N4416 was rejected in Lenexa.
--
Nevin ":-)" Liber
<mailto:nevin@eviloverlord.com <nevin@eviloverlord.com>>
(847) 691-1404
(sent from my iPad)
On Jun 1, 2015, at 5:40 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
It seems to me that, with N4416
<http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4416.pdf> (PDF),
you'd basically have that: a way to know exactly how much memory
std::vector allocated, rather than hoping that vector::reserve didn't
over-allocate.
--
---
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/.
--001a11c3393a17011d05177cba5d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=
=3Dutf-8"></head><body dir=3D"auto"><div>N4416 was rejected in Lenexa.=C2=
=A0<br><br><div>=C2=A0--=C2=A0</div><div>=C2=A0Nevin ":-)" Liber<=
/div><div>=C2=A0<span class=3D"Apple-style-span" style><<a href=3D"mailt=
o:nevin@eviloverlord.com">mailto:nevin@eviloverlord.com</a>></span></div=
><div><span class=3D"Apple-style-span" style>=C2=A0(847) 691-1404</span></d=
iv>(sent from my iPad)</div><div><br>On Jun 1, 2015, at 5:40 PM, Nicol Bola=
s <<a href=3D"mailto:jmckesson@gmail.com">jmckesson@gmail.com</a>> wr=
ote:<br><br></div><blockquote type=3D"cite">It seems to me that, with <a hr=
ef=3D"http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4416.pdf">N4=
416</a> (PDF), you'd basically have that: a way to know exactly how muc=
h memory std::vector allocated, rather than hoping that vector::reserve did=
n't over-allocate.</blockquote></body></html>
<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 />
--001a11c3393a17011d05177cba5d--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 1 Jun 2015 15:56:17 -0700 (PDT)
Raw View
------=_Part_2899_61569601.1433199377879
Content-Type: multipart/alternative;
boundary="----=_Part_2900_1860649800.1433199377879"
------=_Part_2900_1860649800.1433199377879
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Monday, June 1, 2015 at 6:40:08 PM UTC-4, Nicol Bolas wrote:
>
>
>
> On Monday, June 1, 2015 at 3:20:47 PM UTC-4, David Krauss wrote:
>>
>>
>> On 2015=E2=80=9306=E2=80=9302, at 2:12 AM, Matthew Fioravante <fmatth...=
@gmail.com>=20
>> wrote:
>>
>> Also unique_ptr<T[]> does not have any builtin copy semantics.
>>
>>
>> I don=E2=80=99t think dyn_array is ever likely to support copying, eithe=
r. (It=E2=80=99s=20
>> way past my bedtime so maybe I shouldn=E2=80=99t bet against that having=
been=20
>> proposed at some point.)
>>
>> It sounds like what you really want is a non-resizable version of=20
>> std::vector, with a std::piecewise_construct constructor.
>>
>
> It seems to me that, with N4416=20
> <http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4416.pdf>=20
> (PDF), you'd basically have that: a way to know exactly how much memory=
=20
> std::vector allocated, rather than hoping that vector::reserve didn't=20
> over-allocate.
>
Possibility of over-allocating is only one of the many problems.
I know its easier to just tack on some functions to vector than create a=20
whole new class, but is this really the right way to do it? A fixed size=20
array (movable T or not) is a completely different problem then an array=20
that can grow, and different problems should be modelled by different types=
=20
so the compiler can make it impossible for us to make classes of mistakes.
If I'm given a vector from somewhere, I don't know if it is intended to be=
=20
used in an emplace_back_capped() context or an emplace_back() context. Also=
=20
this reserve_initially() business would be better done in the constructor.
Also we're still forced to store a capacity, wasting valuable cache line=20
space. If I have a fixed size array and I can construct all of the elements=
=20
at container construction time using a variadic polymorphic lambda with=20
iterators, I don't need to keep track of the capacity in the container. An=
=20
array type that doesn't even have a push_back(), resize(), etc.. methods=20
can not be used incorrectly.
It also still doesn't solve the general problem of constructing a container=
=20
with non-movable types. Right now it is impossible to specify which=20
constructors and which args to those constructors when building a=20
std::array<NonMovableType,N>.
--=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_2900_1860649800.1433199377879
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, June 1, 2015 at 6:40:08 PM UTC-4, Nicol=
Bolas wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
<br><br>On Monday, June 1, 2015 at 3:20:47 PM UTC-4, David Krauss wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word"><b=
r><div><blockquote type=3D"cite"><div>On 2015=E2=80=9306=E2=80=9302, at 2:1=
2 AM, Matthew Fioravante <<a rel=3D"nofollow">fmatth...@gmail.com</a>>=
; wrote:</div><br><div><div dir=3D"ltr">Also unique_ptr<T[]> does not=
have any builtin copy semantics.<br></div></div></blockquote><div><br></di=
v><div>I don=E2=80=99t think <font face=3D"Courier">dyn_array</font> is eve=
r likely to support copying, either. (It=E2=80=99s way past my bedtime so m=
aybe I shouldn=E2=80=99t bet against that having been proposed at some poin=
t.)</div><div><br></div><div>It sounds like what you really want is a non-r=
esizable version of <font face=3D"Courier">std::vector</font>, with a <font=
face=3D"Courier">std::piecewise_construct</font> constructor.</div></div><=
/div></blockquote><div><br>It seems to me that, with <a href=3D"http://www.=
open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4416.pdf" target=3D"_blank" r=
el=3D"nofollow" onmousedown=3D"this.href=3D'http://www.google.com/url?q\75h=
ttp%3A%2F%2Fwww.open-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2015%2F=
n4416.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNFYm6Uba1_L_5NbkwQNbd-5_1bP3g';=
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%2F2015%2Fn4416.=
pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNFYm6Uba1_L_5NbkwQNbd-5_1bP3g';return=
true;">N4416</a> (PDF), you'd basically have that: a way to know exactly h=
ow much memory std::vector allocated, rather than hoping that vector::reser=
ve didn't over-allocate.</div></div></blockquote><div><br>Possibility of ov=
er-allocating is only one of the many problems.<br><br>I know its easier to=
just tack on some functions to vector than create a whole new class, but i=
s this really the right way to do it? A fixed size array (movable T or not)=
is a completely different problem then an array that can grow, and differe=
nt problems should be modelled by different types so the compiler can make =
it impossible for us to make classes of mistakes.<br><br>If I'm given a vec=
tor from somewhere, I don't know if it is intended to be used in an emplace=
_back_capped() context or an emplace_back() context. Also this reserve_init=
ially() business would be better done in the constructor.<br><br>Also we're=
still forced to store a capacity, wasting valuable cache line space. If I =
have a fixed size array and I can construct all of the elements at containe=
r construction time using a variadic polymorphic lambda with iterators, I d=
on't need to keep track of the capacity in the container. An array type tha=
t doesn't even have a push_back(), resize(), etc.. methods can not be used =
incorrectly.<br><br>It also still doesn't solve the general problem of cons=
tructing a container with non-movable types. Right now it is impossible to =
specify which constructors and which args to those constructors when buildi=
ng a std::array<NonMovableType,N>.<br></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_2900_1860649800.1433199377879--
------=_Part_2899_61569601.1433199377879--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 1 Jun 2015 16:34:32 -0700 (PDT)
Raw View
------=_Part_4217_177766264.1433201672247
Content-Type: multipart/alternative;
boundary="----=_Part_4218_567846071.1433201672247"
------=_Part_4218_567846071.1433201672247
Content-Type: text/plain; charset=UTF-8
Just to make things more clear, here is a possible constructor format for
in-place construction of move-only types. This kind of constructor could be
used for any type, not just a hypothetical fixed_array.
//Class interface
template <typename T, typename A = std::allocator<T>>
class fixed_array {
public:
template <typename F, typename... Iterators>
fixed_array(size_t n, F&& f, Iterators... iters);
//Normal stuff like ::data(), operator[](int), etc...
private:
T* _begin;
T* _end;
};
//Inplace constructor implementation
template <typename T,typename A> template <typename F, typename... Iterators
>
fixed_array<T,A>::fixed_array(size_t n, F&& f, Iterators... iters) {
_begin = this->allocate(n);
_end = _begin + n;
struct Construct {
Construct(A* alloc, T* p) : _alloc(alloc), _ptr(p) {}
template <typename... Args>
T& operator()(Args&&... args) {
_alloc->construct(_ptr, std::forward<Args>(args));
return *_ptr;
}
private:
A* _alloc;
T* _ptr;
};
//exception safety left out for clarify
for(size_t i = 0; i < n; ++i) {
f(Construct(this, _begin + i), std::forward<Iterators>(iterators)...);
advance_all_iterators(iterators...);
}
}
//Usage examples
struct Foo {
Foo();
Foo(int, double);
Foo(string);
Foo(const Foo&) = delete;
Foo& operator=(const Foo&) = delete;
};
auto ci = 0;
auto di = 0;
std::vector<int> iv = { 1, 2, 3 };
std::vector<double> dv = { 1.0, 2.0, 3.0 };
//Default construct 5 foos
auto fa0 = fixed_array<Foo>(5);
//Construct 5 foos using constants
auto fa1 = fixed_array<Foo>(5, [&](auto make) { make(ci, di); });
//Construct 3 foos using a constant and the elements of another container
auto fa2 = fixed_array<Foo>(3, [&](auto make, auto iiter) { make(*iiter,
di); }, iv);
//Construct 3 foos using the elements of 2 different containers
auto fa3 = fixed_array<Foo>(3, [](auto make, auto iiter, auto diter) {
make(*iiter, *diter); }, iv, dv);
//Use different constructors
auto fa4 = fixed_array<Foo>(3, [](auto make, auto iiter, auto diter) {
if(*iiter < 2) { make(*iiter, *diter); } else { make("Hello"); }, iv, dv);
It seems like something like this wouldn't work for aggregates like
std::array. I guess the only solution there would be to allow real
copy/move elision for aggregate initialization.
--
---
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_4218_567846071.1433201672247
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Just to make things more clear, here is a possible constru=
ctor format for in-place construction of move-only types. This kind of cons=
tructor could be used for any type, not just a hypothetical fixed_array.<br=
><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 25=
0); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1p=
x; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">//Class=
interface<br>template</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typ=
ename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">, typename A =
=3D std::allocator<T>></span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> fixed_array </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><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">public</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbs=
p; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
template</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><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> F</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">typename</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: #606;" class=3D"styled-b=
y-prettify">Iterators</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br> fixed_array</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">size_t n</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> F</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
;&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f</=
span><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">Iterators</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> iters</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br><br> </span><span style=3D"col=
or: #800;" class=3D"styled-by-prettify">//Normal stuff like ::data(), opera=
tor[](int), etc...</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">private</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
> T</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> _b=
egin</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nbs=
p; T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> _end</span><sp=
an 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"co=
lor: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br>//Inplace constructor implementati=
on<br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">temp=
late</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> T,typename A</span><sp=
an 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: #000;" class=3D"styled-by-prettify"><code class=3D"prettyprint"><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> F</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: #008;" class=3D"styled-by-pret=
tify">typename</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Iterators</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">></span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></code>f=
ixed_array</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
<</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,A>::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">fixed_array(size_=
t n, F&& f, Iterators... iters) {<br> _begin =3D this-&=
gt;allocate(n);<br> _end =3D _begin + n;<br><br> st=
ruct Construct {<br> Construct(A* alloc, T* p) : _a=
lloc(alloc), _ptr(p) {}<br> template <typename... Arg=
s> <br> T& operator()(Args&&... args) {<b=
r> _alloc->construct(_ptr, std::forw=
ard<Args>(args));<br> return *_pt=
r;<br> }<br> private:<br> &=
nbsp; A* _alloc;<br> T* _ptr;<br> =
};<br><br> //exception safety left out for clarify<br> &n=
bsp; for(size_t i =3D 0; i < n; ++i) {<br> =
f(Construct(this, _begin + i), std::forward<Iterators>(iterators)...=
);<br> advance_all_iterators(iterators...);<b=
r> }<br>}<br><br>//Usage examples<br>struct Foo { <br> Fo=
o();<br> Foo(int, double); <br> Foo(string);<br> Foo(cons=
t Foo&) =3D delete; <br> Foo& operator=3D(const Foo&) =3D=
delete; <br>};<br><br>auto ci =3D 0;<br>auto di =3D 0;<br>std::vector<i=
nt> iv =3D { 1, 2, 3 };<br>std::vector<double> dv =3D { 1.0, 2.0, =
3.0 };<br><br>//Default construct 5 foos<br>auto fa0 =3D fixed_array<Foo=
>(5);<br><br>//Construct 5 foos using constants<br>auto fa1 =3D fixed_ar=
ray<Foo>(5, [&](auto make) { make(ci, di); });<br><br>//Construct=
3 foos using a constant and the elements of another container<br>auto fa2 =
=3D fixed_array<Foo>(3, [&](auto make, auto iiter) { make(*iiter,=
di); }, iv);<br><br>//Construct 3 foos using the elements of 2 different c=
ontainers<br>auto fa3 =3D fixed_array<Foo>(3, [](auto make, auto iite=
r, auto diter) { make(*iiter, *diter); }, iv, dv);<br><br>//Use different c=
onstructors<br>auto fa4 =3D fixed_array<Foo>(3, [](auto make, auto ii=
ter, auto diter) { if(*iiter < 2) { make(*iiter, *diter); } else { make(=
"Hello"); }, iv, dv);<br><br></span></div></code></div><br>It seems like so=
mething like this wouldn't work for aggregates like std::array. I guess the=
only solution there would be to allow real copy/move elision for aggregate=
initialization.<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_4218_567846071.1433201672247--
------=_Part_4217_177766264.1433201672247--
.