Table of Contents
- Summary
- Template Parameters
- Public Member Types
- Public Data Members
- Public Member Functions
- (constructor)
- (destructor)
- operator=
- get_allocator
- key_comp
- value_comp
- begin, cbegin
- end, cend
- rbegin, crbegin
- rend, crend
- nth
- index_of
- empty
- size
- max_size
- capacity
- available
- reserve
- shrink_to_fit
- clear
- emplace
- emplace_hint
- insert
- erase
- swap
- lower_bound
- upper_bound
- equal_range
- find
- count
- contains
- data
- Non-member Functions
Defined in header sfl/small_flat_multiset.hpp
:
namespace sfl
{
template < typename Key,
std::size_t N,
typename Compare = std::less<Key>,
typename Allocator = std::allocator<Key> >
class small_flat_multiset;
}
sfl::small_flat_multiset
is an associative container similar to std::multiset
, but the underlying storage is implemented as a sorted vector.
sfl::small_flat_multiset
internally holds statically allocated array of size N
and stores elements into this array until the number of elements is not greater than N
, which avoids dynamic memory allocation and deallocation. The dynamic memory management is used when the number of elements has to be greater than N
.
The complexity of insertion or removal of elements is O(N). The complexity of search is O(log N).
The elements of sfl::small_flat_multiset
are always stored contiguously in the memory.
Iterators to elements of sfl::small_flat_multiset
are random access iterators and they meet the requirements of LegacyRandomAccessIterator.
sfl::small_flat_multiset
meets the requirements of Container, AllocatorAwareContainer, ReversibleContainer, ContiguousContainer and AssociativeContainer.
-
typename Key
Key type.
-
std::size_t N
Size 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 Compare
Ordering function for keys.
-
typename Allocator
Allocator 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_type
is not the same asKey
.
Member Type | Definition |
---|---|
allocator_type |
Allocator |
allocator_traits |
std::allocator_traits<allocator_type> |
key_type |
Key |
value_type |
Key |
size_type |
typename allocator_traits::size_type |
difference_type |
typename allocator_traits::difference_type |
key_compare |
Compare |
value_compare |
Compare |
reference |
value_type& |
const_reference |
const value_type& |
pointer |
typename allocator_traits::pointer |
const_pointer |
typename allocator_traits::const_pointer |
iterator |
LegacyRandomAccessIterator and LegacyContiguousIterator to const value_type |
const_iterator |
LegacyRandomAccessIterator and LegacyContiguousIterator to const value_type |
reverse_iterator |
std::reverse_iterator<iterator> |
const_reverse_iterator |
std::reverse_iterator<const_iterator> |
static constexpr size_type static_capacity = N;
-
small_flat_multiset() noexcept( std::is_nothrow_default_constructible<Allocator>::value && std::is_nothrow_default_constructible<Compare>::value );
-
explicit small_flat_multiset(const Compare& comp) noexcept( std::is_nothrow_default_constructible<Allocator>::value && std::is_nothrow_copy_constructible<Compare>::value );
-
explicit small_flat_multiset(const Allocator& alloc) noexcept( std::is_nothrow_copy_constructible<Allocator>::value && std::is_nothrow_default_constructible<Compare>::value );
-
explicit small_flat_multiset(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_flat_multiset(InputIt first, InputIt last);
-
template <typename InputIt> small_flat_multiset(InputIt first, InputIt last, const Compare& comp);
-
template <typename InputIt> small_flat_multiset(InputIt first, InputIt last, const Allocator& alloc);
-
template <typename InputIt> small_flat_multiset(InputIt first, InputIt last, const Compare& comp, const Allocator& alloc);
Effects: Constructs an empty container and inserts elements from the range
[first, last)
.Note: These overloads participate in overload resolution only if
InputIt
satisfies requirements of LegacyInputIterator.Complexity: Linear in
std::distance(first, last)
. -
small_flat_multiset(std::initializer_list<value_type> ilist);
-
small_flat_multiset(std::initializer_list<value_type> ilist, const Compare& comp);
-
small_flat_multiset(std::initializer_list<value_type> ilist, const Allocator& alloc);
-
small_flat_multiset(std::initializer_list<value_type> ilist, const Compare& comp, const Allocator& alloc);
Effects: Constructs an empty container and inserts elements from the initializer list
ilist
.Complexity: Linear in
ilist.size()
. -
small_flat_multiset(const small_flat_multiset& other);
-
small_flat_multiset(const small_flat_multiset& other, const Allocator& alloc);
Effects: Copy constructor. Constructs the container with the copy of the contents of
other
.Complexity: Linear in
other.size()
. -
small_flat_multiset(small_flat_multiset&& other);
-
small_flat_multiset(small_flat_multiset&& other, const Allocator& alloc);
Effects: Move constructor. Constructs the container with the contents of
other
using move semantics.other
is not guaranteed to be empty after the move.other
is in a valid but unspecified state after the move.Complexity: Constant in the best case. Linear in
N
in the worst case.
-
~small_flat_multiset();
Effects: Destructs the container. The destructors of the elements are called and the used storage is deallocated.
Complexity: Linear in
size()
.
-
small_flat_multiset& operator=(const small_flat_multiset& other);
Effects: Copy assignment operator. Replaces the contents with a copy of the contents of
other
.Returns:
*this()
.Complexity: Linear in
this->size()
plus linear inother.size()
. -
small_flat_multiset& operator=(small_flat_multiset&& other);
Effects: Move assignment operator. Replaces the contents with those of
other
using move semantics.other
is not guaranteed to be empty after the move.other
is in a valid but unspecified state after the move.Returns:
*this()
.Complexity:
- The best case: Linear in
this->size()
plus constant. - The worst case: Linear in
this->size()
plus linear inother.size()
.
- The best case: Linear in
-
small_flat_multiset& operator=(std::initializer_list<Key> ilist);
Effects: Replaces the contents with those identified by initializer list
ilist
.Returns:
*this()
.Complexity: Linear in
this->size()
plus linear inilist.size()
.
-
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.
-
iterator nth(size_type pos) noexcept;
-
const_iterator nth(size_type pos) const noexcept;
Preconditions:
pos <= size()
Effects: Returns an iterator to the element at position
pos
.If
pos == size()
, the returned iterator is equal toend()
.Complexity: Constant.
-
size_type index_of(const_iterator pos) const noexcept;
Preconditions:
cbegin() <= pos && pos <= cend()
Effects: Returns position of the element pointed by iterator
pos
, i.e.std::distance(begin(), pos)
.If
pos == end()
, the returned value is equal tosize()
.Complexity: Constant.
-
bool empty() const noexcept;
Effects: Returns
true
if 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.
-
size_type capacity() const noexcept;
Effects: Returns the number of elements that the container has currently allocated space for.
Complexity: Constant.
-
size_type available() const noexcept;
Effects: Returns the number of elements that can be inserted into the container without requiring allocation of additional memory.
Complexity: Constant.
-
void reserve(size_type new_cap);
Effects: Tries to increase capacity by allocating additional memory.
If
new_cap > capacity()
, the function allocates memory for new storage of capacity equal to the value ofnew_cap
, moves elements from old storage to new storage, and deallocates memory used by old storage. Otherwise, the function does nothing.This function does not change size of the container.
If the capacity is changed, all iterators and all references to the elements are invalidated. Otherwise, no iterators or references are invalidated.
Complexity: Linear.
Exceptions:
Allocator::allocate
may throw.T
's move or copy constructor may throw.
If an exception is thrown:
- If type
T
has availablenoexcept
move constructor:- This function has no effects (strong exception guarantee).
- Else if type
T
has available copy constructor:- This function has no effects (strong exception guarantee).
- Else if type
T
has available throwing move constructor:- Container is changed but in valid state (basic exception guarantee).
-
void shrink_to_fit();
Effects: Tries to reduce memory usage by freeing unused memory.
-
If
size() > N && size() < capacity()
, the function allocates memory for new storage of capacity equal to the value ofsize()
, moves elements from old storage to new storage, and deallocates memory used by old storage. -
If
size() <= N && N < capacity()
, the function sets new storage to be internal statically allocated array of capacityN
, moves elements from old storage to new storage, and deallocates memory used by old storage. -
Otherwise the function does nothing.
This function does not change size of the container.
If the capacity is changed, all iterators and all references to the elements are invalidated. Otherwise, no iterators or references are invalidated.
Complexity: Linear.
Exceptions:
Allocator::allocate
may throw.T
's move or copy constructor may throw.
If an exception is thrown:
- If type
T
has availablenoexcept
move constructor:- This function has no effects (strong exception guarantee).
- Else if type
T
has available copy constructor:- This function has no effects (strong exception guarantee).
- Else if type
T
has available throwing move constructor:- Container is changed but in valid state (basic exception guarantee).
-
-
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);
Preconditions:
cbegin() <= hint && hint <= cend()
Effects: Inserts a new element into the container.
New element is constructed as
value_type(std::forward<Args>(args)...)
.Iterator
hint
is 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
value
using move semantics.Returns: Iterator to the inserted element.
-
iterator insert(const_iterator hint, const value_type& value);
Preconditions:
cbegin() <= hint && hint <= cend()
Effects: Inserts copy of
value
.Iterator
hint
is 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);
Preconditions:
cbegin() <= hint && hint <= cend()
Effects: Inserts
value
using move semantics.Iterator
hint
is used as a suggestion where to start to search insert position.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
InputIt
satisfies 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())
.
-
iterator erase(iterator pos);
-
iterator erase(const_iterator pos);
Preconditions:
cbegin() <= pos && pos < cend()
Effects: Removes the element at
pos
.Returns: Iterator following the last removed element.
-
iterator erase(const_iterator first, const_iterator last);
Preconditions:
cbegin() <= first && first <= last && last <= cend()
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
key
orx
.Note: Overload (5) participates in overload resolution only if
Compare::is_transparent
exists and is a valid type. It allows calling this function without constructing an instance ofKey
.Returns: Number of elements removed.
-
void swap(small_flat_multiset& other);
Preconditions:
allocator_traits::propagate_on_container_swap::value || get_allocator() == other.get_allocator()
Effects: Exchanges the contents of the container with those of
other
.Complexity: Constant in the best case. Linear in
this->size()
plus linear inother.size()
in the worst case.
-
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
key
orx
. Returnsend()
if no such element is found.Note: Overloads (3) and (4) participate in overload resolution only if
Compare::is_transparent
exists 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
key
orx
. Returnsend()
if no such element is found.Note: Overloads (3) and (4) participate in overload resolution only if
Compare::is_transparent
exists 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
key
orx
.- The first iterator in pair points to the first element that compares not less than
key
orx
. It is equal toend()
if no such element is found. - The second iterator in pair points to the first element that compares greater than
key
orx
. It is equal toend()
is no such element is found.
Note: Overloads (3) and (4) participate in overload resolution only if
Compare::is_transparent
exists 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
key
orx
. 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_transparent
exists 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
key
orx
.Note: Overload (2) participates in overload resolution only if
Compare::is_transparent
exists 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
true
if the container contains an element with key equivalent tokey
orx
, otherwise returnsfalse
.Note: Overload (2) participates in overload resolution only if
Compare::is_transparent
exists and is a valid type. It allows calling this function without constructing an instance ofKey
.Complexity: Logarithmic in
size()
.
-
value_type* data() noexcept;
-
const value_type* data() const noexcept;
Effects: Returns pointer to the underlying array serving as element storage. The pointer is such that range
[data(), data() + size())
is always a valid range, even if the container is empty.data()
is not dereferenceable if the container is empty.Complexity: Constant.
-
template <typename K, std::size_t N, typename C, typename A> bool operator== ( const small_flat_multiset<K, N, C, A>& x, const small_flat_multiset<K, N, C, A>& y );
Effects: Checks if the contents of
x
andy
are equal.The contents of
x
andy
are equal if the following conditions hold:x.size() == y.size()
- Each element in
x
compares equal with the element iny
at the same position.
The comparison is performed by
std::equal
. This comparison ignores the container's orderingCompare
.Returns: Returns
true
if the contents of thex
andy
are equal,false
otherwise.
-
template <typename K, std::size_t N, typename C, typename A> bool operator!= ( const small_flat_multiset<K, N, C, A>& x, const small_flat_multiset<K, N, C, A>& y );
Effects: Checks if the contents of
x
andy
are equal.For details see
operator==
.Returns: Returns
true
if the contents of thex
andy
are not equal,false
otherwise.
-
template <typename K, std::size_t N, typename C, typename A> bool operator< ( const small_flat_multiset<K, N, C, A>& x, const small_flat_multiset<K, N, C, A>& y );
Effects: Compares the contents of
x
andy
lexicographically. The comparison is performed by a functionstd::lexicographical_compare
. This comparison ignores the container's orderingCompare
.Returns:
true
if the contents of thex
are lexicographically less than the contents ofy
,false
otherwise.
-
template <typename K, std::size_t N, typename C, typename A> bool operator> ( const small_flat_multiset<K, N, C, A>& x, const small_flat_multiset<K, 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:
true
if the contents of thex
are lexicographically greater than the contents ofy
,false
otherwise.
-
template <typename K, std::size_t N, typename C, typename A> bool operator<= ( const small_flat_multiset<K, N, C, A>& x, const small_flat_multiset<K, N, C, A>& y );
Effects: Compares the contents of
x
andy
lexicographically. The comparison is performed by a functionstd::lexicographical_compare
. This comparison ignores the container's orderingCompare
.Returns:
true
if the contents of thex
are lexicographically less than or equal to the contents ofy
,false
otherwise.
-
template <typename K, std::size_t N, typename C, typename A> bool operator>= ( const small_flat_multiset<K, N, C, A>& x, const small_flat_multiset<K, N, C, A>& y );
Effects: Compares the contents of
x
andy
lexicographically. The comparison is performed by a functionstd::lexicographical_compare
. This comparison ignores the container's orderingCompare
.Returns:
true
if the contents of thex
are lexicographically greater than or equal to the contents ofy
,false
otherwise.
-
template <typename K, std::size_t N, typename C, typename A> void swap ( small_flat_multiset<K, N, C, A>& x, small_flat_multiset<K, N, C, A>& y );
Effects: Swaps the contents of
x
andy
. Callsx.swap(y)
.
-
template <typename K, std::size_t N, typename C, typename A, typename Predicate> typename small_flat_multiset<K, N, C, A>::size_type erase_if(small_flat_multiset<K, N, C, A>& c, Predicate pred);
Effects: Erases all elements that satisfy the predicate
pred
from the container.pred
is unary predicate which returnstrue
if the element should be removed.Returns: The number of erased elements.
Complexity: Linear.
End of document.