Table of Contents
Defined in header sfl/small_multimap.hpp:
namespace sfl
{
template < typename Key,
typename T,
std::size_t N,
typename Compare = std::less<Key>,
typename Allocator = std::allocator<std::pair<const Key, T>> >
class small_multimap;
}
sfl::small_multimap is an associative container similar to std::multimap, but it internally holds a small amount of statically allocated memory to avoid dynamic memory management when the number of stored elements is small. Dynamic memory management is used when the number of elements exceeds N. This design provides a compact and cache-friendly representation optimized for small sizes.
The underlying storage is implemented as red-black tree.
The complexity of search, insert, and remove operations is O(log N).
References and pointers to elements are stable: insert and erase operations do not invalidate them unless the referenced element is erased.
Iterators to elements are bidirectional iterators, and they meet the requirements of LegacyBidirectionalIterator.
sfl::small_multimap meets the requirements of Container, AllocatorAwareContainer, ReversibleContainer, and AssociativeContainer.
-
typename KeyKey type.
-
typename TValue type.
-
std::size_t NSize of the internal statically allocated array, i.e. the maximal number of elements that can fit into this array.
This parameter can be zero.
-
typename CompareOrdering function for keys.
-
typename AllocatorAllocator used for memory allocation/deallocation and construction/destruction of elements.
This type must meet the requirements of Allocator.
The program is ill-formed if
Allocator::value_typeis not the same asstd::pair<const Key, T>.
| Member Type | Definition |
|---|---|
allocator_type |
Allocator |
key_type |
Key |
mapped_type |
T |
value_type |
std::pair<const Key, T> |
size_type |
Unsigned integer type |
difference_type |
Signed integer type |
key_compare |
Compare |
reference |
value_type& |
const_reference |
const value_type& |
pointer |
Pointer to value_type |
const_pointer |
Pointer to const value_type |
iterator |
LegacyBidirectionalIterator to value_type |
const_iterator |
LegacyBidirectionalIterator to const value_type |
reverse_iterator |
Reverse LegacyBidirectionalIterator to value_type |
const_reverse_iterator |
Reverse LegacyBidirectionalIterator to const value_type |
class value_compare
{
public:
bool operator()(const value_type& x, const value_type& y) const;
};
static constexpr size_type static_capacity = N;
-
small_multimap() noexcept( std::is_nothrow_default_constructible<Allocator>::value && std::is_nothrow_default_constructible<Compare>::value ); -
explicit small_multimap(const Compare& comp) noexcept( std::is_nothrow_default_constructible<Allocator>::value && std::is_nothrow_copy_constructible<Compare>::value ); -
explicit small_multimap(const Allocator& alloc) noexcept( std::is_nothrow_copy_constructible<Allocator>::value && std::is_nothrow_default_constructible<Compare>::value ); -
explicit small_multimap(const Compare& comp, const Allocator& alloc) noexcept( std::is_nothrow_copy_constructible<Allocator>::value && std::is_nothrow_copy_constructible<Compare>::value );Effects: Constructs an empty container.
Complexity: Constant.
-
template <typename InputIt> small_multimap(InputIt first, InputIt last); -
template <typename InputIt> small_multimap(InputIt first, InputIt last, const Compare& comp); -
template <typename InputIt> small_multimap(InputIt first, InputIt last, const Allocator& alloc); -
template <typename InputIt> small_multimap(InputIt first, InputIt last, const Compare& comp, const Allocator& alloc);Effects: Constructs the container with the contents of the range
[first, last).Note: These overloads participate in overload resolution only if
InputItsatisfies requirements of LegacyInputIterator. -
small_multimap(std::initializer_list<value_type> ilist); -
small_multimap(std::initializer_list<value_type> ilist, const Compare& comp); -
small_multimap(std::initializer_list<value_type> ilist, const Allocator& alloc); -
small_multimap(std::initializer_list<value_type> ilist, const Compare& comp, const Allocator& alloc);Effects: Constructs the container with the contents of the initializer list
ilist. -
small_multimap(const small_multimap& other); -
small_multimap(const small_multimap& other, const Allocator& alloc);Effects: Copy constructor. Constructs the container with the copy of the contents of
other. -
small_multimap(small_multimap&& other); -
small_multimap(small_multimap&& other, const Allocator& alloc);Effects: Move constructor. Constructs the container with the contents of
otherusing move semantics.otheris not guaranteed to be empty after the move.otheris in a valid but unspecified state after the move. -
template <typename Range> small_multimap(sfl::from_range_t, Range&& range); -
template <typename Range> small_multimap(sfl::from_range_t, Range&& range, const Compare& comp); -
template <typename Range> small_multimap(sfl::from_range_t, Range&& range, const Allocator& alloc); -
template <typename Range> small_multimap(sfl::from_range_t, Range&& range, const Compare& comp, const Allocator& alloc);Effects: Constructs the container with the contents of
range.Note: It is available in C++11. In C++20 are used proper C++20 range concepts.
-
~small_multimap();Effects: Destructs the container. The destructors of the elements are called and the used storage is deallocated.
Complexity: Linear in
size().
-
small_multimap& operator=(const small_multimap& other);Effects: Copy assignment operator. Replaces the contents with a copy of the contents of
other.Returns:
*this(). -
small_multimap& operator=(small_multimap&& other);Effects: Move assignment operator. Replaces the contents with those of
otherusing move semantics.otheris not guaranteed to be empty after the move.otheris in a valid but unspecified state after the move.Returns:
*this(). -
small_multimap& operator=(std::initializer_list<value_type> ilist);Effects: Replaces the contents with those identified by initializer list
ilist.Returns:
*this().
-
allocator_type get_allocator() const noexcept;Effects: Returns the allocator associated with the container.
Complexity: Constant.
-
key_compare key_comp() const;Effects: Returns the function object that compares the keys, which is a copy of this container's constructor argument
comp.Complexity: Constant.
-
value_compare value_comp() const;Effects: Returns a function object that compares objects of type
value_type.Complexity: Constant.
-
iterator begin() noexcept; -
const_iterator begin() const noexcept; -
const_iterator cbegin() const noexcept;Effects: Returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to
end().Complexity: Constant.
-
iterator end() noexcept; -
const_iterator end() const noexcept; -
const_iterator cend() const noexcept;Effects: Returns an iterator to the element following the last element of the container. This element acts as a placeholder; attempting to access it results in undefined behavior.
Complexity: Constant.
-
reverse_iterator rbegin() noexcept; -
const_reverse_iterator rbegin() const noexcept; -
const_reverse_iterator crbegin() const noexcept;Effects: Returns a reverse iterator to the first element of the reversed container. It corresponds to the last element of the non-reversed container. If the container is empty, the returned iterator is equal to
rend().Complexity: Constant.
-
reverse_iterator rend() noexcept; -
const_reverse_iterator rend() const noexcept; -
const_reverse_iterator crend() const noexcept;Effects: Returns a reverse iterator to the element following the last element of the reversed container. It corresponds to the element preceding the first element of the non-reversed container. This element acts as a placeholder, attempting to access it results in undefined behavior.
Complexity: Constant.
-
bool empty() const noexcept;Effects: Returns
trueif the container has no elements, i.e. whetherbegin() == end().Complexity: Constant.
-
size_type size() const noexcept;Effects: Returns the number of elements in the container, i.e.
std::distance(begin(), end()).Complexity: Constant.
-
size_type max_size() const noexcept;Effects: Returns the maximum number of elements the container is able to hold, i.e.
std::distance(begin(), end())for the largest container.Complexity: Constant.
-
void clear() noexcept;Effects: Erases all elements from the container. After this call,
size()returns zero andcapacity()remains unchanged.Complexity: Linear in
size().
-
template <typename... Args> iterator emplace(Args&&... args);Effects: Inserts a new element into the container.
New element is constructed as
value_type(std::forward<Args>(args)...).Returns: Iterator to the inserted element.
-
template <typename... Args> iterator emplace_hint(const_iterator hint, Args&&... args);Effects: Inserts a new element into the container.
New element is constructed as
value_type(std::forward<Args>(args)...).Iterator
hintis used as a suggestion where to start to search insert position.Returns: Iterator to the inserted element.
-
iterator insert(const value_type& value);Effects: Inserts copy of
value.Returns: Iterator to the inserted element.
-
iterator insert(value_type&& value);Effects: Inserts
valueusing move semantics.Returns: Iterator to the inserted element.
-
template <typename P> iterator insert(P&& value);Effects: Inserts a new element into the container.
New element is constructed as
value_type(std::forward<P>(value)).Note: This overload participates in overload resolution only if
std::is_constructible<value_type, P&&>::valueistrue.Returns: Iterator to the inserted element.
-
iterator insert(const_iterator hint, const value_type& value);Effects: Inserts copy of
value.Iterator
hintis used as a suggestion where to start to search insert position.Returns: Iterator to the inserted element.
-
iterator insert(const_iterator hint, value_type&& value);Effects: Inserts
valueusing move semantics.Iterator
hintis used as a suggestion where to start to search insert position.Returns: Iterator to the inserted element.
-
template <typename P> iterator insert(const_iterator hint, P&& value);Effects: Inserts a new element into the container.
New element is constructed as
value_type(std::forward<P>(value)).Iterator
hintis used as a suggestion where to start to search insert position.Note: This overload participates in overload resolution only if
std::is_constructible<value_type, P&&>::valueistrue.Returns: Iterator to the inserted element.
-
template <typename InputIt> void insert(InputIt first, InputIt last);Effects: Inserts elements from range
[first, last).The call to this function is equivalent to:
while (first != last) { insert(*first); ++first; }Note: This overload participates in overload resolution only if
InputItsatisfies requirements of LegacyInputIterator. -
void insert(std::initializer_list<value_type> ilist);Effects: Inserts elements from initializer list
ilist.The call to this function is equivalent to
insert(ilist.begin(), ilist.end()).
-
template <typename Range> void insert_range(Range&& range);Effects: Inserts elements from
range.Note: It is available in C++11. In C++20 are used proper C++20 range concepts.
-
iterator erase(iterator pos); -
iterator erase(const_iterator pos);Effects: Removes the element at
pos.Returns: Iterator following the last removed element.
-
iterator erase(const_iterator first, const_iterator last);Effects: Removes the elements in the range
[first, last).Returns: Iterator following the last removed element.
-
size_type erase(const Key& key); -
template <typename K> size_type erase(K&& x);Effects: Removes all elements with the key equivalent to
keyorx.Note: Overload (5) participates in overload resolution only if
Compare::is_transparentexists and is a valid type. It allows calling this function without constructing an instance ofKey.Returns: Number of elements removed.
-
void swap(small_multimap& other);Effects: Exchanges the contents of the container with those of
other.
-
iterator lower_bound(const Key& key); -
const_iterator lower_bound(const Key& key) const; -
template <typename K> iterator lower_bound(const K& x); -
template <typename K> const_iterator lower_bound(const K& x) const;Effects: Returns an iterator pointing to the first element with key that compares not less than
keyorx. Returnsend()if no such element is found.Note: Overloads (3) and (4) participate in overload resolution only if
Compare::is_transparentexists and is a valid type. It allows calling these functions without constructing an instance ofKey.Complexity: Logarithmic in
size().
-
iterator upper_bound(const Key& key); -
const_iterator upper_bound(const Key& key) const; -
template <typename K> iterator upper_bound(const K& x); -
template <typename K> const_iterator upper_bound(const K& x) const;Effects: Returns an iterator pointing to the first element with key that compares greater than
keyorx. Returnsend()if no such element is found.Note: Overloads (3) and (4) participate in overload resolution only if
Compare::is_transparentexists and is a valid type. It allows calling these functions without constructing an instance ofKey.Complexity: Logarithmic in
size().
-
std::pair<iterator, iterator> equal_range(const Key& key); -
std::pair<const_iterator, const_iterator> equal_range(const Key& key) const; -
template <typename K> std::pair<iterator, iterator> equal_range(const K& x); -
template <typename K> std::pair<const_iterator, const_iterator> equal_range(const K& x) const;Effects: Returns a range containing all elements with key that compares equivalent to
keyorx.- The first iterator in pair points to the first element that compares not less than
keyorx. It is equal toend()if no such element is found. - The second iterator in pair points to the first element that compares greater than
keyorx. It is equal toend()is no such element is found.
Note: Overloads (3) and (4) participate in overload resolution only if
Compare::is_transparentexists and is a valid type. It allows calling these functions without constructing an instance ofKey.Complexity: Logarithmic in
size(). - The first iterator in pair points to the first element that compares not less than
-
iterator find(const Key& key); -
const_iterator find(const Key& key) const; -
template <typename K> iterator find(const K& x); -
template <typename K> const_iterator find(const K& x) const;Effects: Returns an iterator pointing to the element with key equivalent to
keyorx. Returnsend()if no such element is found. If there are several elements with key in the container, any of them may be returned.Note: Overloads (3) and (4) participate in overload resolution only if
Compare::is_transparentexists and is a valid type. It allows calling these functions without constructing an instance ofKey.Complexity: Logarithmic in
size().
-
size_type count(const Key& key) const; -
template <typename K> size_type count(const K& x) const;Effects: Returns the number of elements with key equivalent to
keyorx.Note: Overload (2) participates in overload resolution only if
Compare::is_transparentexists and is a valid type. It allows calling this function without constructing an instance ofKey.Complexity: Logarithmic in
size()plus linear in the number of the elements found.
-
bool contains(const Key& key) const; -
template <typename K> bool contains(const K& x) const;Effects: Returns
trueif the container contains an element with key equivalent tokeyorx, otherwise returnsfalse.Note: Overload (2) participates in overload resolution only if
Compare::is_transparentexists and is a valid type. It allows calling this function without constructing an instance ofKey.Complexity: Logarithmic in
size().
-
template <typename K, typename T, std::size_t N, typename C, typename A> bool operator== ( const small_multimap<K, T, N, C, A>& x, const small_multimap<K, T, N, C, A>& y );Effects: Checks if the contents of
xandyare equal.The contents of
xandyare equal if the following conditions hold:x.size() == y.size()- Each element in
xcompares equal with the element inyat the same position.
The comparison is performed by
std::equal. This comparison ignores the container's orderingCompare.Returns: Returns
trueif the contents of thexandyare equal,falseotherwise.
-
template <typename K, typename T, std::size_t N, typename C, typename A> bool operator!= ( const small_multimap<K, T, N, C, A>& x, const small_multimap<K, T, N, C, A>& y );Effects: Checks if the contents of
xandyare equal.For details see
operator==.Returns: Returns
trueif the contents of thexandyare not equal,falseotherwise.
-
template <typename K, typename T, std::size_t N, typename C, typename A> bool operator< ( const small_multimap<K, T, N, C, A>& x, const small_multimap<K, T, N, C, A>& y );Effects: Compares the contents of
xandylexicographically. The comparison is performed by a functionstd::lexicographical_compare. This comparison ignores the container's orderingCompare.Returns:
trueif the contents of thexare lexicographically less than the contents ofy,falseotherwise.
-
template <typename K, typename T, std::size_t N, typename C, typename A> bool operator> ( const small_multimap<K, T, N, C, A>& x, const small_multimap<K, T, N, C, A>& y );Effects: Compares the contents of lhs and rhs lexicographically.
The comparison is performed by a function
std::lexicographical_compare. This comparison ignores the container's orderingCompare.Returns:
trueif the contents of thexare lexicographically greater than the contents ofy,falseotherwise.
-
template <typename K, typename T, std::size_t N, typename C, typename A> bool operator<= ( const small_multimap<K, T, N, C, A>& x, const small_multimap<K, T, N, C, A>& y );Effects: Compares the contents of
xandylexicographically. The comparison is performed by a functionstd::lexicographical_compare. This comparison ignores the container's orderingCompare.Returns:
trueif the contents of thexare lexicographically less than or equal to the contents ofy,falseotherwise.
-
template <typename K, typename T, std::size_t N, typename C, typename A> bool operator>= ( const small_multimap<K, T, N, C, A>& x, const small_multimap<K, T, N, C, A>& y );Effects: Compares the contents of
xandylexicographically. The comparison is performed by a functionstd::lexicographical_compare. This comparison ignores the container's orderingCompare.Returns:
trueif the contents of thexare lexicographically greater than or equal to the contents ofy,falseotherwise.
-
template <typename K, typename T, std::size_t N, typename C, typename A> void swap ( small_multimap<K, T, N, C, A>& x, small_multimap<K, T, N, C, A>& y );Effects: Swaps the contents of
xandy. Callsx.swap(y).
-
template <typename K, typename T, std::size_t N, typename C, typename A, typename Predicate> typename small_multimap<K, T, N, C, A>::size_type erase_if(small_multimap<K, T, N, C, A>& c, Predicate pred);Effects: Erases all elements that satisfy the predicate
predfrom the container.predis unary predicate which returnstrueif the element should be removed.Returns: The number of erased elements.
End of document.