std::flat_set(3)
π
std::flat_set β C++ Standard Libary (manual page std::flat_set(3)) π
hey bestie π welcome to the std::flat_set(3) page. yes, the header spells it βC++ Standard Libaryβ β keeping the typo, it's iconic π«Ά. this is the whole manual page, same facts, way more group-chat energy. let's go β¨
π NAME π
std::flat_set β std::flat_set (yes, that's literally what the NAME section says π).
πΈ Synopsis πΈ
Defined in header <flat_set>
template<
class Key,
class Compare = std::less<Key>, (since C++23)
class KeyContainer = std::vector<Key>
> class flat_set;
The flat set is a container adaptor that gives the functionality of an associative container that stores a sorted set of unique objects of type Key. Sorting is done using the key comparison function Compare.
The class template flat_set acts as a wrapper to the underlying sorted container passed as object of type KeyContainer.
Everywhere the standard library uses the Compare requirements, uniqueness is determined by using the equivalence relation. Informally, two objects a and b are considered equivalent if neither compares less than the other: !comp(a, b) && !comp(b, a).
std::flat_set meets the requirements of Container, ReversibleContainer, optional container requirements, and all requirements of AssociativeContainer (including logarithmic search complexity), except that:
- requirements related to nodes are not applicable,
- iterator invalidation requirements differ,
- the complexity of insertion and erasure operations is linear.
A flat set supports most AssociativeContainer's operations that use unique keys.
π§© Template parameters π§©
Keyβ The type of the stored elements. The program is ill-formed ifKeyis not the same type asKeyContainer::value_type.Compareβ AComparetype providing a strict weak ordering.KeyContainerβ The type of the underlyingSequenceContainerto store the elements. The iterators of such container should satisfyLegacyRandomAccessIteratoror modelrandom_access_iterator. The standard containersstd::vectorandstd::dequesatisfy these requirements.
π Member types π
container_typeβKeyContainerkey_typeβKeyvalue_typeβKeykey_compareβComparevalue_compareβComparereferenceβvalue_type&const_referenceβconst value_type&size_typeβtypename KeyContainer::size_typedifference_typeβtypename KeyContainer::difference_typeiteratorβ implementation-definedLegacyRandomAccessIteratorandrandom_access_iteratortovalue_typeconst_iteratorβ implementation-definedLegacyRandomAccessIteratorandrandom_access_iteratortoconst value_typereverse_iteratorβstd::reverse_iterator<iterator>const_reverse_iteratorβstd::reverse_iterator<const_iterator>
π¦ Member objects π¦
c(private) β the underlying container ofcontainer_type(exposition-only member object*)compare(private) β the comparison function object of typekey_compare(exposition-only member object*)
β¨ Member functions β¨
constructorβ constructs theflat_set(public member function)destructor(implicitly declared) β destroys every element of the container adaptor (public member function)operator=β assigns values to the container adaptor (public member function)
π Iterators π
beginβ returns an iterator to the beginning (public member function)cbeginβ (public member function)endβ returns an iterator to the end (public member function)cendβ (public member function)rbeginβ returns a reverse iterator to the beginning (public member function)crbeginβ (public member function)rendβ returns a reverse iterator to the end (public member function)crendβ (public member function)
π Capacity π
emptyβ checks whether the container adaptor is empty (public member function)sizeβ returns the number of elements (public member function)max_sizeβ returns the maximum possible number of elements (public member function)
π Modifiers π
emplaceβ constructs element in-place (public member function)emplace_hintβ constructs elements in-place using a hint (public member function)insertβ inserts elements (public member function)insert_rangeβ inserts a range of elements (public member function)extractβ extracts the underlying container (public member function)replaceβ replaces the underlying container (public member function)eraseβ erases elements (public member function)swapβ swaps the contents (public member function)clearβ clears the contents (public member function)
π Lookup π
findβ finds element with specific key (public member function)countβ returns the number of elements matching specific key (public member function)containsβ checks if the container contains element with specific key (public member function)lower_boundβ returns an iterator to the first element not less than the given key (public member function)upper_boundβ returns an iterator to the first element greater than the given key (public member function)equal_rangeβ returns range of elements matching a specific key (public member function)
π Observers π
key_compβ returns the function that compares keys (public member function)value_compβ returns the function that compares keys in objects of typevalue_type(public member function)
π Non-member functions π
operator==β lexicographically compares the values of twoflat_setsoperator<=>β(function template)(C++23)std::swap(std::flat_set)β specializes thestd::swapalgorithm;(C++23)(function template)erase_if(std::flat_set)β erases all elements satisfying specific criteria;(C++23)(function template)
π«Ά Helper classes π«Ά
std::uses_allocator<std::flat_set>β specializes thestd::uses_allocatortype trait;(C++23)(class template specialization)
π·οΈ Tags π·οΈ
sorted_unique,sorted_unique_t(tag)(C++23)β indicates that elements of a range are sorted and unique.
π§ Deduction guides π§
- nothing listed here on the page π«Ά. the heading exists, but no entries follow it.
π Notes π
The member types iterator and const_iterator may be aliases to the same type. This means defining a pair of function overloads using the two types as parameter types may violate the One Definition Rule. Since iterator is convertible to const_iterator, a single function with a const_iterator as parameter type will work instead.
Some advantages of flat set over other standard container adaptors are:
- Potentially faster lookup (even though search operations have logarithmic complexity).
- Much faster iteration: random access iterators instead of bidirectional iterators.
- Less memory consumption for small objects (and for big objects if
KeyContainer::shrink_to_fit()is available). - Better cache performance (depending on
KeyContainer, keys are stored in a contiguous block(s) of memory).
Some disadvantages of flat set are:
- Non-stable iterators (iterators are invalidated when inserting and erasing elements).
- Non-copyable and non-movable type values can not be stored.
- Weaker exception safety (copy/move constructors can throw when shifting values in erasures and insertions).
- Slower (i.e. linear) insertion and erasure, especially for non-movable types.
Feature-test macro
__cpp_lib_flat_setβ value202207L, std(C++23), featurestd::flat_set and std::flat_multiset.
π¨ Example π¨
This section is incomplete Reason: no example
π See also π
flat_multisetβ adapts a container to provide a collection of keys, sorted by keys;(C++23)(class template)setβ collection of unique keys, sorted by keys;(class template)unordered_setβ collection of unique keys, hashed by keys;(C++11)(class template)
ποΈ Categories ποΈ
- Todo without reason
- Todo no example
okay that's the whole manual page, bestie π«Άβ¨ source/version/date shoutout: http://cppreference.com, 2024.06.10, page std::flat_set(3). periodt π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms