Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulties in implementing flat_meow's exception guarantees #4059

Closed
achabense opened this issue Sep 29, 2023 · 1 comment
Closed

Difficulties in implementing flat_meow's exception guarantees #4059

achabense opened this issue Sep 29, 2023 · 1 comment
Labels
flat_meow C++23 container adaptors LWG issue needed A wording defect that should be submitted to LWG as a new issue resolved Successfully resolved without a commit

Comments

@achabense
Copy link
Contributor

achabense commented Sep 29, 2023

I find it very hard to meet the exception guarantees for flat_meow (take flat_set for example below).

https://eel.is/c++draft/flat.set#overview-2:
flat_set meets the requirements of an associative container ([associative.reqmts]), except that: ...

According to this, flat_set should meet the exception guarantees specified in

https://eel.is/c++draft/containers#associative.reqmts.except:
erase(k) does not throw an exception unless that exception is thrown by the container's Compare object (if any)
if an exception is thrown by any operation from within an insert or emplace function inserting a single element, the insertion has no effect.

flat_set relies on its underlying containers to do insert and erase. So, the above requirements also imply:

A. The container should not throw on erase(iter).
~ However, this is not true for deque and vector:

https://eel.is/c++draft/containers#deque.modifiers-5:
Throws: Nothing unless an exception is thrown by the assignment operator of T.
https://eel.is/c++draft/containers#vector.modifiers-4:
Throws: Nothing unless an exception is thrown by the assignment operator or move assignment operator of T.

B. The container should provide strong guarantee for insert(iter,single-element).
~ However, for example, this is not required by deque. The wordings doesn't specify the effects when not inserting at beginning or end.

https://eel.is/c++draft/containers#deque.modifiers-3:
If an exception is thrown while inserting a single element at either end, there are no effects. Otherwise, if an exception is thrown by the move constructor of a non-Cpp17CopyInsertable T, the effects are unspecified.

I think the standard should give explicit specifications for exception guarantees for flat_meow::insert/erase. What's more, this is also related to flat_meow's invariant guarantee against exceptions. As different containers provides different level of exception guarantee, what should flat_meow behave when an exception of unknown effect occurs in insert/erase functions?

https://eel.is/c++draft/flat.set#overview-6:
If any member function in [flat.set.defn] exits via an exception, the invariant is restored.

@CaseyCarter CaseyCarter added the LWG issue needed A wording defect that should be submitted to LWG as a new issue label Sep 29, 2023
@StephanTLavavej StephanTLavavej added the flat_meow C++23 container adaptors label Oct 3, 2023
@frederick-vs-ja
Copy link
Contributor

LWG-4046 is filed.

@CaseyCarter CaseyCarter added the resolved Successfully resolved without a commit label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flat_meow C++23 container adaptors LWG issue needed A wording defect that should be submitted to LWG as a new issue resolved Successfully resolved without a commit
Projects
None yet
Development

No branches or pull requests

4 participants