Reference
namespace eggs {
template <
typename Value,
auto Key,
typename Compare = std::less<key-type>,
typename Allocator = std::allocator<Value>
>
class keyed_set;
} // namespace eggs
Class template keyed_set
An ordered associative container satisfying the C++26
AssociativeContainer requirements that stores unique Value
objects indexed by a member designated by the non-type template parameter
Key.
Template parameters:
- Value — the element type.
- Key — a pointer-to-member of
Value. The pointee type becomeskey_type. - Compare — a strict-weak-ordering binary predicate on
key_type. Defaults tostd::less<key_type>. IfCompare::is_transparentis defined, heterogeneous lookup by arbitraryKis enabled. - Allocator — allocator for
Value. Defaults tostd::allocator<Value>.
Member Types
-
key_type- The type of the member pointed to by
Key, with cv-qualifiers and references removed.
- The type of the member pointed to by
-
value_typeValue
-
key_compareCompare— the user-supplied comparison object, operating onkey_type.
-
value_compare- An internal projecting adaptor wrapping
Comparethat comparesvalue_typeobjects by their projected key. Always definesis_transparent.
- An internal projecting adaptor wrapping
-
allocator_typeAllocator
-
iterator/const_iterator- A constant bidirectional iterator. Elements may not be mutated through iterators as doing so could corrupt the ordering invariant.
iteratorandconst_iteratorare the same type.
- A constant bidirectional iterator. Elements may not be mutated through iterators as doing so could corrupt the ordering invariant.
-
node_type/insert_return_type- Node handle and node insertion result types.
Constructors
-
keyed_set()- Constructs an empty container using
key_compare()as comparison object.
- Constructs an empty container using
-
explicit keyed_set(key_compare const& c, allocator_type const& a = {})- Constructs an empty container using
cas comparison object andaas allocator.
- Constructs an empty container using
-
explicit keyed_set(allocator_type const& a)- Constructs an empty container using the given allocator.
-
keyed_set(InputIt first, InputIt last, key_compare const& c = {}, allocator_type const& a = {})- Constructs a container from the range
[first, last). Duplicate keys are ignored.
- Constructs a container from the range
-
keyed_set(std::initializer_list<value_type> il, key_compare const& c = {}, allocator_type const& a = {})- Constructs a container from an initializer list. Duplicate keys are ignored.
-
keyed_set(std::from_range_t, R&& rg, key_compare const& c = {}, allocator_type const& a = {})- Constructs a container from a
container-compatible-range. Available when__cpp_lib_ranges_to_containeris defined.
- Constructs a container from a
-
keyed_set(keyed_set const&)/keyed_set(keyed_set&&)- Copy and move constructors. Allocator-extended forms are also provided.
Modifiers
-
emplace(Args&&...) -> pair<iterator, bool>- Constructs a new element in-place. Returns
{position, true}on insertion,{position, false}on duplicate.
- Constructs a new element in-place. Returns
-
emplace_hint(const_iterator hint, Args&&...) -> iterator- Constructs in-place near
hint. A wrong hint is accepted; the result is always correct.
- Constructs in-place near
-
insert(value_type const&) -> pair<iterator, bool>
insert(value_type&&) -> pair<iterator, bool>
insert(const_iterator hint, value_type)
insert(InputIt first, InputIt last)
insert(initializer_list)
insert(node_type&&) -> insert_return_type- Inserts if no element with an equivalent key exists. For node-handle insertion, an unconsumed node handle is returned in the result on duplicate.
-
insert_range(R&& rg)- Inserts all elements of
rgfor which no equivalent key exists. Available when__cpp_lib_ranges_to_containeris defined.
- Inserts all elements of
-
extract(const_iterator) -> node_type
extract(key_type const&) -> node_type- Removes and returns the element as a node handle without copy or move. Returns an empty handle if not found. All pointers and references to the element remain valid while held in the handle.
-
erase(key_type const&) -> size_type
erase(const_iterator) -> iterator
erase(const_iterator first, const_iterator last) -> iterator- Removes the designated element(s). Key overloads return the count erased (0 or 1). Iterator overloads return an iterator past the last erased element.
-
clear()- Erases all elements. Postcondition:
empty().
- Erases all elements. Postcondition:
-
merge(keyed_set&)/merge(keyed_set&&)- Transfers elements from
sourcefor which no equivalent key exists. No copy or move of values occurs. All iterators and pointers to transferred elements remain valid.
- Transfers elements from
Observers
-
key_comp() -> key_compare- Returns the
Compareobject, operating onkey_type.
- Returns the
-
value_comp() -> value_compare- Returns the projecting comparator, operating on
value_type.
- Returns the projecting comparator, operating on
-
get_allocator() -> allocator_type- Returns the stored allocator.
Lookup
-
find(key_type const&) -> const_iterator
find(K const&) -> const_iterator(requires transparent Compare)- Returns an iterator to the element whose key is equivalent to
k, orend(). O(log n).
- Returns an iterator to the element whose key is equivalent to
-
count(key_type const&) -> size_type
count(K const&) -> size_type- Returns the number of matching elements (0 or 1).
-
contains(key_type const&) -> bool
contains(K const&) -> bool- Returns
trueif a matching element exists. Equivalent tofind(k) != end().
- Returns
-
lower_bound(key_type const&) -> const_iterator
upper_bound(key_type const&) -> const_iterator- Returns an iterator to the first element whose key is not less than / greater than
k, orend(). Transparent overloads available whenCompare::is_transparentis defined.
- Returns an iterator to the first element whose key is not less than / greater than
-
equal_range(key_type const&) -> pair<const_iterator, const_iterator>- Returns
{lower_bound(k), upper_bound(k)}. Since keys are unique the range contains at most one element. Transparent overload available.
- Returns
Swap
-
swap(keyed_set&)/swap(keyed_set&, keyed_set&)- Exchanges the contents. All iterators, pointers, and references remain valid and refer to the same elements in the swapped container.
Comparison
-
operator==(keyed_set const&, keyed_set const&) -> bool- Returns
trueif both containers have equal size and all corresponding elements compare equal underkey_type::operator==.
- Returns
-
operator<=>(keyed_set const&, keyed_set const&)- Lexicographic three-way comparison over key projections. Synthesises
<,<=,>,>=.
- Lexicographic three-way comparison over key projections. Synthesises

