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

[flat.map.capacity]: Where are the other flat_meow's correspondences about this? #6641

Open
hewillk opened this issue Nov 5, 2023 · 1 comment

Comments

@hewillk
Copy link
Contributor

hewillk commented Nov 5, 2023

Only flat_map has an additional [flat.map.capacity] to specify the implementation of size/max_size member:

size_type size() const noexcept;
-1- Returns: c.keys.size().

size_type max_size() const noexcept;
-2- Returns: min<size_type>(c.keys.max_size(), c.values.max_size()).

However, flat_multimap, flat_set, and flat_multiset have no corresponding sections. Where does this inconsistency come from?

In addition, since all flat_meows are adaptors containing the underlying container, I can't understand why their empty/size/max_size/clear are all noexcept. According to the Lakos Rule, they should not be declared noexcept because the implementation should be by calling the member functions of the underlying container, and these functions are not guaranteed to be noexcept.
(I believe the standard seems to pay great attention to complying with the Lakos Rule, this is also reflected in the non-noexcept empty/size of the stack/queue).

Not quite sure what I'm missing with the above.

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Nov 6, 2023

In addition, since all flat_meows are adaptors containing the underlying container, I can't understand why their empty/size/max_size/clear are all noexcept. According to the Lakos Rule, they should not be declared noexcept because the implementation should be by calling the member functions of the underlying container, and these functions are not guaranteed to be noexcept.

The noexcept specifications don't seem to violate the Lakos Rule. These functions are required to have no preconditions and be non-failing ([container.reqmts], [sequence.reqmts], [associative.reqmts.general], [unord.req.general]).

(I believe the standard seems to pay great attention to complying with the Lakos Rule, this is also reflected in the non-noexcept empty/size of the stack/queue).

This may be an oversight.

N3187 said that empty should be noexcept because "it depends on iterator comparison which cannot throw for library provided iterators". However, the iterator comparison may eventually involve user-provided fancy pointers (see also LWG2261), of which comparison is not required to be noexcept, but merely not to throw when the comparison is well-defined.

Similarly, do we need to make exception specifications for move constructors of containers more conditional, just because copy/move construction of fancy pointers are not required to be noexcept?

Given there're already some noexcept functions that don't (or even can't) always avoid calling non-noexcept underlying operations, I think empty and size of all container adaptors should be noexcept. Let's submit an LWG issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants