Boost logo

Boost :

Subject: Re: [boost] [flat_set] When to sort?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2017-03-27 16:15:48


AMDG

On 03/26/2017 05:03 PM, Vladimir Batov via Boost wrote:
>
> On 03/27/2017 09:20 AM, Andrey Semashev wrote:
>> On Mon, Mar 27, 2017 at 12:01 AM, Vladimir Batov via Boost
>>
>>>> flat_set< int > fs;
>>>> fs.reserve(5);
>>>> fs.insert(10);
>>>> auto it1 = fs.begin();
>>>> auto it2 = fs.insert(42).first;
>>>> auto it3 = f2.begin(); // invalidates it1 and it2
>>> Well, I do understand that insertion into a std::vector invalidates the
>>> iterators. I thought you argued (when you said "No, this won't work in
>>> general because...") that "my" approach (of only sorting on when-needed
>>> basis) had different to the flat_set behavior.
>> I did, and the example above shows where your proposed change breaks
>> the previously valid code.
>
> I have to disagree with your "proposed change breaks the previously
> valid code" statement. Indeed, given we know the implementation of
> flat_set, we can say that the above code does work with the current
> flat_set implementation. However, the code is not guaranteed to work
> with the current flat_set.

Invalidating it1 may be fine. Invalidating
it2 is a definitely not okay.

In Christ,
Steven Watanabe


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