Boost logo

Boost :

Subject: Re: [boost] C++03 unique_ptr emulation
From: David Abrahams (dave_at_[hidden])
Date: 2009-01-08 14:53:34


on Thu Jan 08 2009, "Daniel James" <daniel_james-AT-fmail.co.uk> wrote:

> 2009/1/8 Howard Hinnant <hinnant_at_[hidden]>:
>>
>> Is it practical to do this instead?
>>
>> class vector
>> {
>> void push_back(value_type x); // internally move construct from x
>> }
>
> I was doing this (which is inspired by either Adobe or David Abrahams):
>
> template <class U>
> void push_back(U const& x, typename boost::copy_sink<U, T>::type = 0) {
> if(data_.end_ == data_.storage_end_) resize(data_.begin_ ?
> size() * 2 : 4);
> std::uninitialized_fill_n(data_.end_, 1, x);
> ++data_.end_;
> }
>
> #if !defined(BOOST_NO_SFINAE)
>
> template <class U>
> void push_back(U x, typename boost::move_sink<U, T>::type = 0) {
> if(data_.end_ == data_.storage_end_) resize(data_.begin_ ?
> size() * 2 : 4);
> data_.end_ = boost::uninitialized_move(&x, &x + 1, data_.end_);
> }
>
> #endif

Those xxx_sink things are Adobe's. I never liked them, but they solve
problems to which I've never found a better answer. I believe they are
the current state of the art.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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