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 10:44:27


On Wed, Sep 16, 2015 at 9:23 AM, Thorsten Ottosen <tottosen_at_[hidden]> wrote:
> On 16-09-2015 14:13, Sam Kellett wrote:
>>>
>>>
>>>> [snip]
>>>
>>>
>>>
>>>
>>> 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)};
>>>
>
> Well, almost.
>
> IMO, we need three things to make it perfect:
>
> A. flat_set/map should have an additional template argument specifying the
> internal vector type (it can default to the current choice).
>
> B. You should be able to move the whole container, as suggested.
>
> C. The constructor should contain an assertion with a call to is_sorted()

So essentially, flat_set/map would now be an adapter like a stack or queue.
Makes sense. About C, I rather think that we should have two constructors:

flat_set/map(storage raw)
flat_set/map(ordered_unique_range_t, storage sorted)

and then the is_sorted() assert check should be done in the second
constructor, and the first one would call sort().

-- 
François

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