Table of Contents
Defined in header sfl/static_unordered_flat_multimap.hpp
:
namespace sfl
{
template < typename Key,
typename T,
std::size_t N,
typename KeyEqual = std::equal_to<Key> >
class static_unordered_flat_multimap;
}
sfl::static_unordered_flat_multimap
is an associative container similar to std::unordered_multimap
, but the capacity is fixed and the underlying storage is implemented as an unsorted vector.
sfl::static_unordered_flat_multimap
internally holds statically allocated array of size N
and stores elements into this array, which avoids dynamic memory allocation and deallocation. This container never uses dynamic memory management.
The number of elements in static flat unordered multimap cannot be greater than N
. Attempting to insert more than N
elements into this container results in undefined behavior.
The complexity of insertion or removal of elements is O(1). The complexity of search is O(N).
The elements of sfl::static_unordered_flat_multimap
are always stored contiguously in the memory.
Iterators to elements of sfl::static_unordered_flat_multimap
are random access iterators and they meet the requirements of LegacyRandomAccessIterator.
sfl::static_unordered_flat_multimap
meets the requirements of Container and ContiguousContainer. The requirements of UnorderedAssociativeContainer are partionally met.
This container is convenient for bare-metal embedded software development.
-
typename Key
Key type.
-
typename T
Value type.
-
std::size_t N
Size of the internal statically allocated array, i.e. the maximal number of elements that this container can contain.
-
typename KeyEqual
Function for comparing keys.
Member Type | Definition |
---|---|
key_type |
Key |
mapped_type |
T |
value_type |
std::pair<Key, T> |
size_type |
std::size_t |
difference_type |
std::ptrdiff_t |
key_equal |
KeyEqual |
reference |
value_type& |
const_reference |
const value_type& |
pointer |
value_type* |
const_pointer |
const value_type* |
iterator |
LegacyRandomAccessIterator and LegacyContiguousIterator to value_type |
const_iterator |
LegacyRandomAccessIterator and LegacyContiguousIterator to const value_type |
class value_equal
{
public:
bool operator()(const value_type& x, const value_type& y) const;
};
static constexpr size_type static_capacity = N;
-
static_unordered_flat_multimap() noexcept(std::is_nothrow_default_constructible<KeyEqual>::value)
-
explicit static_unordered_flat_multimap(const KeyEqual& equal) noexcept(std::is_nothrow_copy_constructible<KeyEqual>::value)
Effects: Constructs an empty container.
-
template <typename InputIt> static_unordered_flat_multimap(InputIt first, InputIt last);
-
template <typename InputIt> static_unordered_flat_multimap(InputIt first, InputIt last, const KeyEqual& equal);
Preconditions:
std::distance(first, last) <= capacity()
Effects: Constructs an empty container and inserts elements from the range
[first, last)
.Note: This overload participates in overload resolution only if
InputIt
satisfies requirements of LegacyInputIterator.Complexity: Linear in
std::distance(first, last)
. -
static_unordered_flat_multimap(std::initializer_list<value_type> ilist);
-
static_unordered_flat_multimap(std::initializer_list<value_type> ilist, const KeyEqual& equal);
Preconditions:
ilist.size() <= capacity()
Effects: Constructs an empty container and inserts elements from the initializer list
ilist
.Complexity: Linear in
ilist.size()
. -
static_unordered_flat_multimap(const static_unordered_flat_multimap& other);
Effects: Copy constructor. Constructs the container with the copy of the contents of
other
.Complexity: Linear in size.
-
static_unordered_flat_multimap(static_unordered_flat_multimap&& other);
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: Linear in size.
-
~static_unordered_flat_multimap();
Effects: Destructs the container. The destructors of the elements are called and the used storage is deallocated.
Complexity: Linear in size.
-
static_unordered_flat_multimap& operator=(const static_unordered_flat_multimap& other);
Effects: Copy assignment operator. Replaces the contents with a copy of the contents of
other
.Returns:
*this()
.Complexity: Linear in size.
-
static_unordered_flat_multimap& operator=(static_unordered_flat_multimap&& 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: Linear in size.
-
static_unordered_flat_multimap& operator=(std::initializer_list<value_type> ilist);
Preconditions:
ilist.size() <= capacity()
Effects: Replaces the contents with those identified by initializer list
ilist
.Returns:
*this()
.Complexity: Linear in size.
-
key_equal key_eq() const;
Effects: Returns the function object that compares keys for equality, which is a copy of this container's constructor argument
equal
.Complexity: Constant.
-
value_equal value_eq() 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.
-
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.
-
bool full() const noexcept;
Effects: Returns
true
if the container is full, i.e. whethersize() == capacity()
.Complexity: Constant.
-
size_type size() const noexcept;
Effects: Returns the number of elements in the container, i.e.
std::distance(begin(), end())
.Complexity: Constant.
-
static constexpr size_type max_size() const noexcept;
Effects: Returns the maximum number of elements the container is able to hold, i.e.
N
.Complexity: Constant.
-
static constexpr size_type capacity() const noexcept;
Effects: Returns the maximum number of elements the container is able to hold, i.e.
N
.Complexity: Constant.
-
size_type available() const noexcept;
Effects: Returns the number of elements that can be inserted into the container, i.e.
capacity() - size()
.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);
Preconditions:
!full()
Effects: Inserts a new element into the container.
New element is constructed as
value_type(std::forward<Args>(args)...)
.Note: The behavior is undefined if preconditions are not satisfied.
Returns: Iterator to the inserted element.
-
template <typename... Args> iterator emplace_hint(const_iterator hint, Args&&... args);
Preconditions:
!full()
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.Iterator
hint
is ignored due to container's underlying storage implementation. This overload exists just to have this container compatible with standard C++ containers as much as possible.Returns: Iterator to the inserted element.
-
iterator insert(const value_type& value);
Preconditions:
!full()
Effects: Inserts copy of
value
.Returns: Iterator to the inserted element.
-
iterator insert(value_type&& value);
Preconditions:
!full()
Effects: Inserts
value
using move semantics.Returns: Iterator to the inserted element.
-
template <typename P> iterator insert(P&& value);
Preconditions:
!full()
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&&>::value
istrue
.Returns: Iterator to the inserted element.
-
iterator insert(const_iterator hint, const value_type& value);
Preconditions:
!full()
cbegin() <= hint && hint <= cend()
Effects: Inserts copy of
value
.Iterator
hint
is used as a suggestion where to start to search insert position.Iterator
hint
is ignored due to container's underlying storage implementation. This overload exists just to have this container compatible with standard C++ containers as much as possible.Returns: Iterator to the inserted element.
-
iterator insert(const_iterator hint, value_type&& value);
Preconditions:
!full()
cbegin() <= hint && hint <= cend()
Effects: Inserts
value
using move semantics.Iterator
hint
is used as a suggestion where to start to search insert position.Iterator
hint
is ignored due to container's underlying storage implementation. This overload exists just to have this container compatible with standard C++ containers as much as possible.Returns: Iterator to the inserted element.
-
template <typename P> iterator insert(const_iterator hint, P&& value);
Preconditions:
!full()
cbegin() <= hint && hint <= cend()
Effects: Inserts a new element into the container.
New element is constructed as
value_type(std::forward<P>(value))
.Iterator
hint
is used as a suggestion where to start to search insert position.Iterator
hint
is ignored due to container's underlying storage implementation. This overload exists just to have this container compatible with standard C++ containers as much as possible.Note: This overload participates in overload resolution only if
std::is_constructible<value_type, P&&>::value
istrue
.Returns: Iterator to the inserted element.
-
template <typename InputIt> void insert(InputIt first, InputIt last);
Preconditions:
std::distance(first, last) <= available()
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);
Preconditions:
ilist.size() <= available()
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
KeyEqual::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(static_unordered_flat_multimap& other);
Effects: Exchanges the contents of the container with those of
other
.Complexity: Linear in size.
-
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
KeyEqual::is_transparent
exists and is a valid type. It allows calling these functions without constructing an instance ofKey
.Complexity: Constant in the best case. Linear in
size()
in the worst case.
-
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
KeyEqual::is_transparent
exists and is a valid type. It allows calling this function without constructing an instance ofKey
.Complexity: Linear in
size()
.
-
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
KeyEqual::is_transparent
exists and is a valid type. It allows calling this function without constructing an instance ofKey
.Complexity: Constant in the best case. Linear in
size()
in the worst case.
-
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, typename T, std::size_t N, typename E> bool operator== ( const static_unordered_flat_multimap<K, T, N, E>& x, const static_unordered_flat_multimap<K, T, N, E>& 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()
- For each element in
x
there is equal element iny
.
The comparison is performed by
std::is_permutation
. This comparison ignores the container'sKeyEqual
function.Returns:
true
if the contents of thex
andy
are equal,false
otherwise.
-
template <typename K, typename T, std::size_t N, typename E> bool operator!= ( const static_unordered_flat_multimap<K, T, N, E>& x, const static_unordered_flat_multimap<K, T, N, E>& y );
Effects: Checks if the contents of
x
andy
are equal.For details see
operator==
.Returns:
true
if the contents of thex
andy
are not equal,false
otherwise.
-
template <typename K, typename T, std::size_t N, typename E> void swap ( static_unordered_flat_multimap<K, T, N, E>& x, static_unordered_flat_multimap<K, T, N, E>& y );
Effects: Swaps the contents of
x
andy
. Callsx.swap(y)
.
-
template <typename K, typename T, std::size_t N, typename E, typename Predicate> typename static_unordered_flat_multimap<K, T, N, E>::size_type erase_if(static_unordered_flat_multimap<K, T, N, E>& 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.