You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In flat_set::assign, the container only provides the basic exception guarantee if memory cannot be stolen from the input and the ::reserve() allocation throws. In addition, since input_view does not specify that its value_type is nothrow move or copyable, the operation may again fail during the translation of elements from the view into the set.
array_.clear();
array_.reserve(input.size()); // <-- might throw here, leaving the container empty// insert all elements individuallyfor (auto& element : input.view())
{
if (input.will_copy())
insert(element); // <-- could also throw here, leaving a partially filled containerelse
{
// safe, according to precondition of input view,// we're allowed to move themauto& non_const = const_cast<Key&>(element);
insert(std::move(non_const)); // <-- or here
}
}
It looks like you are already aware of this, given the TODO comments in flat_map's assign* functions:
I need to think about my exception safety policy for this library first, before fixing it. Right now I'm tending to providing the strong exception safety if a type has nothrow move constructors.
In flat_set::assign, the container only provides the basic exception guarantee if memory cannot be stolen from the input and the ::reserve() allocation throws. In addition, since input_view does not specify that its value_type is nothrow move or copyable, the operation may again fail during the translation of elements from the view into the set.
It looks like you are already aware of this, given the TODO comments in flat_map's assign* functions:
A simple solution to add strong exception safety would be to create a new flat_set from the input range and swap if there was no exception thrown.
The text was updated successfully, but these errors were encountered: