Boost logo

Boost :

Subject: Re: [boost] [container] moving a pre-built vector into a flat_set
From: Francois Duranleau (xiao.bai.xiong_at_[hidden])
Date: 2015-09-16 08:08:04


On Wed, Sep 16, 2015 at 4:19 AM, Sam Kellett <samkellett_at_[hidden]> wrote:
> On 16 September 2015 at 01:24, Chris Glover <c.d.glover_at_[hidden]> wrote:
>
>> <snip>
>>
>> >
>> > what i would like to be able to do is move the vector straight into the
>> > flat_set, something like:
>> >
>> > std::vector<T> data;
>> >
>> > flat_set data_set1(std::move(data)) // move vector in and sort it
>> > // or:
>> > std::sort(data.begin(), data.end()); // sort vector
>> > flat_set data_set2(ordered_unique_t, std::move(data)) // and move it in
>> >
>> > is this doable (am i just being blind?) or is there plans/interest for
>> > this?
>> >
>>
>> </snip>
>>
>> You'll probably never be able to move the whole allocation, but you might
>> be able to move each element via std::make_move_iterator
>>
>
> how come? i get that it's exposing the implementation, but the gains would
> be so so massive. and the name flat_ basically confirms the use of a sorted
> vector internally.

Moving in a std::vector would force the flat_set to be implemented in terms of a
std::vector. However, what about a type from flat_set, e.g. flat_set<T>::storage
and document what concept this storage implements (e.g. Random Access
Container), and then we could do what you want in a maybe cleaner way.

flat_set<T>::storage data;
// fill data
flat_set<T> the_set{std::move(data)};

-- 
François

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