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

Initial implementation of P1222R1 flat_set from Zach Laine's paper #148

Closed
wants to merge 32 commits into from

Conversation

Quuxplusone
Copy link
Contributor

From this paper: P1222R1 "A Standard flat_set" (January 2019).

Notice that some of the wording is actually in P0429R6 "A Standard flat_map" (January 2019), so you need to look at both papers.

Needs tests, of course!

TODO comments mark the places where there are bugs in P1222R1 and they aren't 100% obvious typos. (I quietly fixed several 100% obvious typos.)

GCC eagerly evaluates expressions cast to `void`,
but correctly lazily evaluates expressions comma'ed to `void`.
https://godbolt.org/z/FPovlu
…ntainers.

The old wording was in terms of "default-construct a KeyContainer `temp`,
then swap it with `c`." The swap will have undefined behavior whenever
`temp`'s default-constructed allocator is not equal to `c`'s allocator.
This is generally expected to be the case when KeyContainer is anything
with `std::pmr` in the name (e.g. `std::pmr::vector`).

tzlaine/draft#5
    flat_set.h(291): warning C4459:
    declaration of 'sorted_unique' hides global declaration

This diagnostic seems crazy aggressive, but, okay then.
Eliminate calls to std::forward and std::move for compilation speed.
And drive-by fix a build failure on my local Xcode by moving
the declaration of this `operator<` above the reference to a
template instantiation that causes `operator<` to be looked up.
No idea whether this is sane, but it works.
The result type of `std::rbegin(c_)` might not be the same as
`std::reverse_iterator<decltype(c_.begin())>`, so we'd better
be explicit.

Also, use `c_.begin()` instead of `std::begin(c_)` everywhere
for consistency. (All container types have a `.begin()` method.)
- The non-`sorted_unique` constructors/inserters must not only sort
  the container but unique it also.

- The swap operation can assume that the container is nothrow-swappable,
  but not that the comparator is.

- After a successful `extract()`, the container must be emptied
  (not left in a valid-but-unspecified state) in order to preserve
  our sorted-and-uniqued invariant.

Implementation note:
In C++14 we have to provide our own `is_nothrow_swappable` because otherwise
we would either incorrectly tag our swap as `noexcept` when it could throw
(leading to aborts), or incorrectly tag our swap as `noexcept(false)`
when it should actually have been `noexcept` (which is almost worse).
This is really horrible. I'm not at all convinced that I'm doing
the right thing here.

tzlaine/flat_map#11
And fix a missing `return` in the two-iterator `erase` method.
@Quuxplusone
Copy link
Contributor Author

Squash-merged 8df31aa (both flat_set and flat_map).

@Quuxplusone Quuxplusone closed this Jun 6, 2019
@Quuxplusone Quuxplusone deleted the flatset branch July 12, 2023 21:01
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

Successfully merging this pull request may close these issues.

1 participant