Boost logo

Boost :

Subject: Re: [boost] [container] varray aka static_vector
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-02-12 17:22:36


2013/2/12 Andrew Hundt <athundt_at_[hidden]>

> On Tue, Feb 12, 2013 at 3:02 PM, Krzysztof Czainski <1czajnik_at_[hidden]
> >wrote:
>
> > 2013/2/12 Nevin Liber <nevin_at_[hidden]>
> >
> > > On 12 February 2013 09:10, Krzysztof Czainski <1czajnik_at_[hidden]>
> > wrote:
> > > > However, I'd rather there was a new member function for "noinit"
> > > > pushing/resizing. Just like the emplace* family of functions was
> added,
> > > > while the push* family was left alone ;-)
> >
> > Anyway, personally I'm only interested in features, that can be added for
> > C++03 ;-) And noinit_push*/noinit_resize (enabled_if< is_pod<value_type>
> >)
> > are things I have use cases for.
>
>
> Could you explain a little more about why emplace_back is not sufficient? I
> believe it includes rvalue reference emulation for C++03.
>

Sure:

struct X { int a; double b; }
typedef boost::container::vector<X> V; // or varray<X,5> or some other
container ;-)
V v;
v.emplace_back(); // unnecessarily zero-initializes memory
v.back().a = 1; v.back().b = 3.14;

If emplace_back() didn't zero-initialize PODs, it would be inconsistent
with std containers, and therefore surprising, so I suggest a new function
for this. Same for resize().

Or perhaps if not a new member function, maybe an overload for a noinit
tag, used like so:

v.emplace_back( noinit );

With noinit defined in the library something like:
struct noinit_t {};
noinit_t const noinit = {};

Regards,
Kris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk