Eggs.KeyedSet

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:

Member Types

  • key_type
    • The type of the member pointed to by Key, with cv-qualifiers and references removed.
  • value_type
    • Value
  • key_compare
    • Compare — the user-supplied comparison object, operating on key_type.
  • value_compare
    • An internal projecting adaptor wrapping Compare that compares value_type objects by their projected key. Always defines is_transparent.
  • allocator_type
    • Allocator
  • iterator / const_iterator
    • A constant bidirectional iterator. Elements may not be mutated through iterators as doing so could corrupt the ordering invariant. iterator and const_iterator are the same type.
  • 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.
  • explicit keyed_set(key_compare const& c, allocator_type const& a = {})
    • Constructs an empty container using c as comparison object and a as allocator.
  • 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.
  • 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_container is defined.
  • 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.
  • emplace_hint(const_iterator hint, Args&&...) -> iterator
    • Constructs in-place near hint. A wrong hint is accepted; the result is always correct.
  • 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 rg for which no equivalent key exists. Available when __cpp_lib_ranges_to_container is defined.
  • 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().
  • merge(keyed_set&) / merge(keyed_set&&)
    • Transfers elements from source for which no equivalent key exists. No copy or move of values occurs. All iterators and pointers to transferred elements remain valid.

Observers

  • key_comp() -> key_compare
    • Returns the Compare object, operating on key_type.
  • value_comp() -> value_compare
    • Returns the projecting comparator, operating on value_type.
  • 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, or end(). O(log n).
  • 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 true if a matching element exists. Equivalent to find(k) != end().
  • 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, or end(). Transparent overloads available when Compare::is_transparent is defined.
  • 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.

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 true if both containers have equal size and all corresponding elements compare equal under key_type::operator==.
  • operator<=>(keyed_set const&, keyed_set const&)
    • Lexicographic three-way comparison over key projections. Synthesises <, <=, >, >=.