Cpp Utilities 1.2.3
|
Key-value container behaves like std::map, but extended with random-access operations and traverses in the sequence order of value appends like std::vector
.
More...
#include <SequencialMap.hpp>
Classes | |
struct | iterator_base |
Base type for iterators. More... | |
struct | key_iterator |
Iterator to traverse keys. More... | |
struct | SerializeManipulator |
Stream manipulator for serialization and deserialization. More... | |
Public Types | |
using | allocator_type = Allocator |
Provide same member type of std::map . More... | |
using | map_type = std::map< Key, T, Compare, Allocator > |
Underlying map type for map APIs. More... | |
using | vector_type = std::vector< typename map_type::iterator > |
Underlying map type for random-access operations and sequencial traversal. More... | |
using | key_type = typename map_type::key_type |
Provide same member type of std::map . More... | |
using | mapped_type = typename map_type::mapped_type |
Provide same member type of std::map . More... | |
using | key_compare = typename map_type::key_compare |
Provide same member type of std::map . More... | |
using | value_compare = typename map_type::value_compare |
Provide same member type of std::map . More... | |
using | value_type = typename map_type::value_type |
Provide same member type of std::map . More... | |
using | pointer = typename map_type::pointer |
Provide same member type of std::map . More... | |
using | const_pointer = typename map_type::const_pointer |
Provide same member type of std::map . More... | |
using | reference = typename map_type::reference |
Provide same member type of std::map . More... | |
using | const_reference = typename map_type::const_reference |
Provide same member type of std::map . More... | |
using | size_type = typename map_type::size_type |
Provide same member type of std::map . More... | |
using | difference_type = typename map_type::difference_type |
Provide same member type of std::map . More... | |
using | iterator = iterator_base< false > |
Mutable iterator type for LegacyRandomAccessIterator . More... | |
using | const_iterator = iterator_base< true > |
Immutable iterator type for constant LegacyRandomAccessIterator . More... | |
using | reverse_iterator = std::reverse_iterator< iterator > |
Mutable reverse iterator type. More... | |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Immutable reverse iterator type. More... | |
using | reverse_key_iterator = std::reverse_iterator< key_iterator > |
Reverse iterator to traverse keys. More... | |
Public Member Functions | |
SequencialMap () | |
Default constructor, constructs an empty container. More... | |
SequencialMap (const Compare &comp, const Allocator &alloc=Allocator()) | |
Constructs an empty container with given comparator and allocator. More... | |
template<typename InputIt > | |
SequencialMap (InputIt first, InputIt last, const Compare &comp=Compare(), const Allocator &alloc=Allocator()) | |
Constructs the container with the contents of the range [first, last) . If multiple elements in the range have keys that compare equivalent, only the first element is inserted. More... | |
template<typename InputIt > | |
SequencialMap (InputIt first, InputIt last, const Allocator &alloc) | |
Constructs the container with the contents of the range [first, last) . If multiple elements in the range have keys that compare equivalent, only the first element is inserted. More... | |
SequencialMap (const SequencialMap &other, const Allocator &alloc=Allocator()) | |
Copy constructor. Constructs the container with the copy of the contents of other . If alloc is not provided, allocator is obtained by calling ```cpp std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.get_allocator()) ```. More... | |
SequencialMap (SequencialMap &&other, const Allocator &alloc=Allocator()) | |
Move constructor. Constructs the container with the contents of other using move semantics. If alloc is not provided, allocator is obtained by move-construction from the allocator belonging to other . More... | |
SequencialMap (std::initializer_list< value_type > init, const Compare &comp=Compare(), const Allocator &alloc=Allocator()) | |
Constructs the container with the contents of the initializer list init . If multiple elements in the range have keys that compare equivalent, only the first element is inserted. More... | |
~SequencialMap ()=default | |
Destructs the container. The destructors of the elements are called and the used storage is deallocated. Note, that if the elements are pointers, the pointed-to objects are not destroyed. More... | |
allocator_type | get_allocator () const |
Returns the allocator associated with the container. More... | |
bool | empty () const noexcept |
Checks if the container has no elements, i.e. whether begin() == end() . More... | |
size_type | size () const noexcept |
Returns the number of elements in the container, i.e. std::distance(begin(), end()) . More... | |
size_type | max_size () const noexcept |
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container. More... | |
void | clear () noexcept |
bool | contains (const key_type &key) const |
Checks if there is an element with key equivalent to key in the container. More... | |
iterator | find (const key_type &key) |
Finds an element with key equivalent to key. More... | |
const_iterator | find (const key_type &key) const |
Finds an element with key equivalent to key. More... | |
template<typename Container = std::vector<key_type>> | |
Container | keys () const |
Returns a list containing all the keys in the map in the sequence order of value appends. More... | |
const key_type | key (const T &value, const key_type &defaultKey=key_type()) const |
Returns the key with value value , or defaultKey if the map contains no item with value value . More... | |
template<typename Container = std::vector<T>> | |
Container | values () const |
Returns a list containing all the values in the map in the sequence order of value appends. More... | |
const T & | value (const key_type &key, const T &defaultValue=T()) const |
Returns the value associated with the key key . More... | |
reference | at (size_type pos) |
Returns a reference to the element at specified location pos , with bounds checking. More... | |
const_reference | at (size_type pos) const |
Returns a const reference to the element at specified location pos , with bounds checking. More... | |
T & | operator[] (const key_type &key) |
Returns a reference to the value that is mapped to a key equivalent to key , performing an insertion if such key does not already exist. More... | |
T & | operator[] (key_type &&key) |
Returns a reference to the value that is mapped to a key equivalent to key , performing an insertion if such key does not already exist. More... | |
const T | operator[] (const key_type &key) const |
Returns a copy to the value that is mapped to a key equivalent to key , return a default constructed value if such key does not already exist. More... | |
const T | operator[] (key_type &&key) const |
Returns a copy to the value that is mapped to a key equivalent to key , return a default constructed value if such key does not already exist. More... | |
reference | front () |
Returns a reference to the first element in the container. More... | |
const_reference | front () const |
Returns a const reference to the first element in the container. More... | |
reference | back () |
Returns a reference to the last element in the container. More... | |
const_reference | back () const |
Returns a const reference to the last element in the container. More... | |
SequencialMap | mid (size_type pos) const |
Returns a sub-map which contains elements from this map, starting at position pos to the end. More... | |
SequencialMap | mid (size_type pos, size_type length) const |
Returns a sub-map which contains elements from this map, starting at position pos , with length elements (or all remaining elements if there are less than length elements) are included. More... | |
std::pair< iterator, bool > | push_back (const_reference value) |
Appends the given element value to the end of the container, if the container doesn't already contain an element with an equivalent key. More... | |
std::pair< iterator, bool > | push_back (value_type &&value) |
Appends the given element value to the end of the container, if the container doesn't already contain an element with an equivalent key. More... | |
std::pair< iterator, bool > | push_back (const key_type &key, const T &value) |
Appends the given element value to the end of the container, if the container doesn't already contain an element with an equivalent key. More... | |
std::pair< iterator, bool > | push_back (const key_type &key, T &&value) |
Appends the given element value to the end of the container, if the container doesn't already contain an element with an equivalent key. More... | |
void | push_back (const SequencialMap &other) |
Appends all elements from given container other to the end of the container, ignores all values with keys already exists in the container. More... | |
void | push_back (std::initializer_list< value_type > ilist) |
Appends all elements from initializer list ilist to the end of the container, ignores all values with keys already exists in the container. More... | |
template<typename InputIt > | |
void | push_back (InputIt first, InputIt last) |
Appends all elements from from range [first, last) to the end of the container, ignores all values with keys already exists in the container. More... | |
template<typename... Args> | |
std::pair< iterator, bool > | emplace_back (const key_type &key, Args &&... args) |
Appends a new element to the end of the container. More... | |
template<typename... Args> | |
std::pair< iterator, bool > | emplace_back (key_type &&key, Args &&... args) |
Appends a new element to the end of the container. More... | |
SequencialMap | operator+ (const SequencialMap &other) const |
Same as push_back, appends all elements from given container other to the end of the container, ignores all values with keys already exists in the container. More... | |
SequencialMap | operator+ (SequencialMap &&other) const |
Same as push_back, appends all elements from given container other to the end of the container, ignores all values with keys already exists in the container. More... | |
SequencialMap & | operator+= (const SequencialMap &other) |
Same as push_back, appends all elements from given container other to the end of the container and return *this , ignores all values with keys already exists in the container. More... | |
SequencialMap & | operator+= (SequencialMap &&other) |
Same as push_back, appends all elements from given container other to the end of the container and return *this , ignores all values with keys already exists in the container. More... | |
iterator | insert (size_t pos, const_reference value) |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key. More... | |
iterator | insert (size_t pos, value_type &&value) |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key. More... | |
iterator | insert (size_t pos, const key_type &key, const T &value) |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key. More... | |
iterator | insert (size_t pos, const key_type &key, T &&value) |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key. More... | |
iterator | insert (iterator pos, const_reference value) |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key. More... | |
iterator | insert (iterator pos, value_type &&value) |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key. More... | |
iterator | insert (iterator pos, const key_type &key, const T &value) |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key. More... | |
iterator | insert (iterator pos, const key_type &key, T &&value) |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key. More... | |
template<typename InputIt > | |
void | insert (size_t pos, InputIt first, InputIt last) |
Inserts elements into the container, if the container doesn't already contain an element with an equivalent key. More... | |
void | insert (size_t pos, std::initializer_list< value_type > ilist) |
Inserts elements into the container, if the container doesn't already contain an element with an equivalent key. More... | |
template<typename InputIt > | |
void | insert (iterator pos, InputIt first, InputIt last) |
Inserts elements into the container, if the container doesn't already contain an element with an equivalent key. More... | |
void | insert (iterator pos, std::initializer_list< value_type > ilist) |
Inserts elements into the container, if the container doesn't already contain an element with an equivalent key. More... | |
template<typename... Args> | |
std::pair< iterator, bool > | emplace_at (size_t pos, const key_type &key, Args &&... args) |
Inserts a new element to the container as close as possible to the position just before hint. The element is constructed in-place, i.e. no copy or move operations are performed. More... | |
template<typename... Args> | |
std::pair< iterator, bool > | emplace_at (size_t pos, key_type &&key, Args &&... args) |
Inserts a new element to the container as close as possible to the position just before hint. The element is constructed in-place, i.e. no copy or move operations are performed. More... | |
template<typename... Args> | |
iterator | emplace_hint (const_iterator hint, key_type &&key, Args &&... args) |
Inserts a new element to the container as close as possible to the position just before hint. The element is constructed in-place, i.e. no copy or move operations are performed. More... | |
void | pop_back () |
Removes the last element of the container. More... | |
void | erase (const key_type &key) |
Removes specified element from the container. More... | |
void | erase (size_type pos, size_type count=1) |
Removes specified elements from the container. More... | |
iterator | erase (const_iterator pos) |
Removes specified elements from the container. More... | |
iterator | erase (const_iterator first, const_iterator last) |
Removes specified elements from the container. More... | |
iterator | begin () |
Returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to end() . More... | |
const_iterator | begin () const |
Returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to end() . More... | |
const_iterator | cbegin () const |
Returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to end() . More... | |
iterator | end () |
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. More... | |
const_iterator | end () const |
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. More... | |
const_iterator | cend () const |
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. More... | |
reverse_iterator | rbegin () |
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() . More... | |
const_reverse_iterator | rbegin () const |
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() . More... | |
const_reverse_iterator | crbegin () const |
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() . More... | |
reverse_iterator | rend () |
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. More... | |
const_reverse_iterator | rend () const |
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. More... | |
const_reverse_iterator | crend () const |
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. More... | |
key_iterator | key_begin () const |
Returns an iterator to the first key of the container. If the container is empty, the returned iterator will be equal to end() . More... | |
key_iterator | key_end () const |
Returns an iterator to the key following the last key of the container. This key acts as a placeholder; attempting to access it results in undefined behavior. More... | |
reverse_key_iterator | key_rbegin () const |
Returns a reverse iterator to the first key of the reversed container. It corresponds to the last key of the non-reversed container. If the container is empty, the returned iterator is equal to rend() . More... | |
reverse_key_iterator | key_rend () const |
Returns a reverse iterator to the key following the last key of the reversed container. It corresponds to the key preceding the first key of the non-reversed container. This key acts as a placeholder, attempting to access it results in undefined behavior. More... | |
SequencialMap & | operator= (const SequencialMap &other) |
Replaces the contents of the input container. More... | |
SequencialMap & | operator= (SequencialMap &&other) |
Replaces the contents of the input container. More... | |
SequencialMap & | operator= (std::initializer_list< value_type > ilist) |
Replaces the contents of the input container. More... | |
bool | operator== (const SequencialMap &other) const |
Checks if the contents of two containers are not equal. More... | |
bool | operator!= (const SequencialMap &other) const |
Checks if the contents of two containers are equal, that is,. More... | |
bool | operator< (const SequencialMap &other) const |
Compares the contents of two containers lexicographically. More... | |
bool | operator<= (const SequencialMap &other) const |
Compares the contents of two containers lexicographically. More... | |
bool | operator> (const SequencialMap &other) const |
Compares the contents of two containers lexicographically. More... | |
bool | operator>= (const SequencialMap &other) const |
Compares the contents of two containers lexicographically. More... | |
void | swap (SequencialMap &other) |
Exchanges the contents of the container with those of other. Does not invoke any move, copy, or swap operations on individual elements. More... | |
key_compare | key_comp () const |
Returns the function object that compares the keys, which is a copy of this container's constructor argument comp. More... | |
value_compare | value_comp () const |
Returns a function object that compares objects of type std::map::value_type (key-value pairs) by using key_comp to compare the first components of the pairs. More... | |
SerializeManipulator | serialize () const |
Serialize the contents to output stream. More... | |
SerializeManipulator | deserialize () |
Deserialize the contents from input stream. More... | |
Friends | |
template<typename Stream > | |
Stream & | operator<< (Stream &out, const SequencialMap &map) |
Writes the contents of list to output stream. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename Key , typename T , typename Compare = std::less<Key>, typename Allocator = std::allocator<std::pair<const Key, T>>> | |
void | swap (Container::SequencialMap< Key, T, Compare, Allocator > &lhs, Container::SequencialMap< Key, T, Compare, Allocator > &rhs) noexcept |
Specializes the std::swap algorithm. More... | |
template<class Key , class T , class Compare , class Alloc , class Pred > | |
void | erase_if (Container::SequencialMap< Key, T, Compare, Alloc > &c, Pred pred) |
Erases all elements that satisfy the predicate pred from the container. More... | |
Key-value container behaves like std::map, but extended with random-access operations and traverses in the sequence order of value appends like std::vector
.
Key | Key type of input maps. |
T | Value type of input maps. |
Compare | Comparison function object to use for all comparisons of keys. |
Allocator | Allocator to use for all memory allocations of this container. |
Same API as std::map
, but add more APIs from std::vector
to extend random-access operations.
All iterators and random-access operations traverse the map in the sequence of value appends like std::vector
.
Iterator and Reference Invalidation
Iterator invalidation of modify operations behave like std::vector
.
Reference invalidation of modify operations behave like std::map
.
Algorithmic Complexity
Most operations of SequencialMap have the same algorithmic complexity as std::map
, while random-access operations share the same complexity as std::vector
.
std::vector
, because moved values are std::map::iterator
, not acture T
node.)using Container::SequencialMap< Key, T, Compare, Allocator >::allocator_type = Allocator |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::map_type = std::map<Key, T, Compare, Allocator> |
Underlying map type for map APIs.
using Container::SequencialMap< Key, T, Compare, Allocator >::vector_type = std::vector<typename map_type::iterator> |
Underlying map type for random-access operations and sequencial traversal.
using Container::SequencialMap< Key, T, Compare, Allocator >::key_type = typename map_type::key_type |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::mapped_type = typename map_type::mapped_type |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::key_compare = typename map_type::key_compare |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::value_compare = typename map_type::value_compare |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::value_type = typename map_type::value_type |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::pointer = typename map_type::pointer |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::const_pointer = typename map_type::const_pointer |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::reference = typename map_type::reference |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::const_reference = typename map_type::const_reference |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::size_type = typename map_type::size_type |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::difference_type = typename map_type::difference_type |
Provide same member type of std::map
.
using Container::SequencialMap< Key, T, Compare, Allocator >::iterator = iterator_base<false> |
Mutable iterator type for LegacyRandomAccessIterator
.
using Container::SequencialMap< Key, T, Compare, Allocator >::const_iterator = iterator_base<true> |
Immutable iterator type for constant LegacyRandomAccessIterator
.
using Container::SequencialMap< Key, T, Compare, Allocator >::reverse_iterator = std::reverse_iterator<iterator> |
Mutable reverse iterator type.
using Container::SequencialMap< Key, T, Compare, Allocator >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Immutable reverse iterator type.
using Container::SequencialMap< Key, T, Compare, Allocator >::reverse_key_iterator = std::reverse_iterator<key_iterator> |
Reverse iterator to traverse keys.
|
inline |
Default constructor, constructs an empty container.
|
inlineexplicit |
Constructs an empty container with given comparator and allocator.
comp | Comparison function object given for this container. |
alloc | Allocator given for this container. |
|
inline |
Constructs the container with the contents of the range [first, last)
. If multiple elements in the range have keys that compare equivalent, only the first element is inserted.
first | Iterator to the first element to copy from. |
last | Iterator after the last element to copy from. |
comp | Comparison function object given for this container. |
alloc | Allocator given for this container. |
|
inline |
Constructs the container with the contents of the range [first, last)
. If multiple elements in the range have keys that compare equivalent, only the first element is inserted.
first | Iterator to the first element to copy from. |
last | Iterator after the last element to copy from. |
alloc | Allocator given for this container. |
|
inline |
Copy constructor. Constructs the container with the copy of the contents of other
. If alloc
is not provided, allocator is obtained by calling ```cpp std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.get_allocator()) ```.
other | Another container to be used as source to initialize the elements of the container with. |
alloc | Allocator given for this container. |
|
inline |
Move constructor. Constructs the container with the contents of other
using move semantics. If alloc is not provided, allocator is obtained by move-construction from the allocator belonging to other
.
other | Another container to be used as source to initialize the elements of the container with. |
alloc | Allocator given for this container. |
|
inline |
Constructs the container with the contents of the initializer list init
. If multiple elements in the range have keys that compare equivalent, only the first element is inserted.
init | Initializer list with value_type elements. |
comp | Comparison function object given for this container. |
alloc | Allocator given for this container. |
|
default |
Destructs the container. The destructors of the elements are called and the used storage is deallocated. Note, that if the elements are pointers, the pointed-to objects are not destroyed.
|
inline |
Returns the allocator associated with the container.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end())
for the largest container.
This value typically reflects the theoretical limit on the size of the container, at most std::numeric_limits<difference_type>::max()
. At runtime, the size of the container may be limited to a value smaller than max_size()
by the amount of RAM available.
Complexity
Constant.
|
inlinenoexcept |
@brief Erases all elements from the container. After this call, size()
returns zero.
Invalidates any references, pointers, or iterators referring to contained elements. Any past-the-end iterator remains valid.
Complexity
Linear in the size of the container, i.e., the number of elements.
|
inline |
Checks if there is an element with key equivalent to key in the container.
key | Key value of the element to search for. |
true
if there is such an element, otherwise false
.Complexity
Logarithmic in the size of the container.
|
inline |
Finds an element with key equivalent to key.
key | Key value of the element to search for. |
key
. If no such element is found, past-the-end (see end()
) iterator is returned.Complexity
Logarithmic in the size of the container.
|
inline |
Finds an element with key equivalent to key.
key | Key value of the element to search for. |
key
. If no such element is found, past-the-end (see end()
) iterator is returned.Complexity
Logarithmic in the size of the container.
|
inline |
Returns a list containing all the keys in the map in the sequence order of value appends.
Container | Vector-like container to contain return keys. |
The order is guaranteed to be the same as that used by values()
.
Complexity
Linear in the size of the container, i.e., the number of elements.
|
inline |
Returns the key with value value
, or defaultKey
if the map contains no item with value value
.
value | Value to find key from. |
defaultKey | Default return if the map contains no item with value value . |
value
, or defaultKey
if the map contains no item with value value
.This function can be slow(linear time), because its internal data structure is optimized for fast lookup by key, not by value.
Complexity
Linear in the size of the container, i.e., the number of elements.
|
inline |
Returns a list containing all the values in the map in the sequence order of value appends.
Container | Vector-like container to contain return values. |
The order is guaranteed to be the same as that used by values()
.
Complexity
Linear in the size of the container, i.e., the number of elements.
|
inline |
Returns the value associated with the key key
.
key | Key to find value from. |
defaultValue | Default return value if the map contains no item with key key . |
value
, or defaultKey
if the map contains no item with value value
.If the map contains no item with key key
, the function returns defaultValue
.
Complexity
Logarithmic in the size of the container.
|
inline |
Returns a reference to the element at specified location pos
, with bounds checking.
pos | Position of the element to return |
std::out_of_range | If pos is not within the range of the container, i.e. if !(pos < size()) , an exception of type std::out_of_range is thrown. |
Complexity
Constant.
|
inline |
Returns a const reference to the element at specified location pos
, with bounds checking.
pos | Position of the element to return |
std::out_of_range | If pos is not within the range of the container, i.e. if !(pos < size()) , an exception of type std::out_of_range is thrown. |
Complexity
Constant.
|
inline |
Returns a reference to the value that is mapped to a key equivalent to key
, performing an insertion if such key does not already exist.
key | The key of the element to find. |
key
existed. Otherwise a reference to the mapped value of the existing element whose key is equivalent to key
.Complexity
Logarithmic in the size of the container.
|
inline |
Returns a reference to the value that is mapped to a key equivalent to key
, performing an insertion if such key does not already exist.
key | The key of the element to find. |
key
existed. Otherwise a reference to the mapped value of the existing element whose key is equivalent to key
.Complexity
Logarithmic in the size of the container.
|
inline |
Returns a copy to the value that is mapped to a key equivalent to key
, return a default constructed value if such key does not already exist.
key | The key of the element to find. |
key
existed. Otherwise a default constructed value is returned.Complexity
Logarithmic in the size of the container.
|
inline |
Returns a copy to the value that is mapped to a key equivalent to key
, return a default constructed value if such key does not already exist.
key | The key of the element to find. |
key
existed. Otherwise a default constructed value is returned.Complexity
Logarithmic in the size of the container.
|
inline |
Returns a reference to the first element in the container.
Complexity
Constant.
|
inline |
Returns a const reference to the first element in the container.
Complexity
Constant.
|
inline |
Returns a reference to the last element in the container.
Complexity
Constant.
|
inline |
Returns a const reference to the last element in the container.
Complexity
Constant.
|
inline |
Returns a sub-map which contains elements from this map, starting at position pos
to the end.
pos | First element position. |
pos
.Complexity
Linear in the size of the return container, i.e., the number of elements starting from pos
.
|
inline |
Returns a sub-map which contains elements from this map, starting at position pos
, with length
elements (or all remaining elements if there are less than length
elements) are included.
pos | First element position. |
length | Elements numbers from pos to be included. |
length
elements starting at position pos
.Complexity
Linear in the size of the return container, i.e., the number of length
.
|
inline |
Appends the given element value to the end of the container, if the container doesn't already contain an element with an equivalent key.
value | The element to append. |
bool
denoting whether the insertion took place.Complexity
Logarithmic in the size of the container.
|
inline |
Appends the given element value to the end of the container, if the container doesn't already contain an element with an equivalent key.
value | The element to append. |
bool
denoting whether the insertion took place.Complexity
Logarithmic in the size of the container.
|
inline |
Appends the given element value to the end of the container, if the container doesn't already contain an element with an equivalent key.
key | The key of the element to append. |
value | The value of the element to append. |
bool
denoting whether the insertion took place.Complexity
Logarithmic in the size of the container.
|
inline |
Appends the given element value to the end of the container, if the container doesn't already contain an element with an equivalent key.
key | The key of the element to append. |
value | The value of the element to append. |
bool
denoting whether the insertion took place.Complexity
Logarithmic in the size of the container.
|
inline |
Appends all elements from given container other
to the end of the container, ignores all values with keys already exists in the container.
other | Another container to append all elements from. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
|
inline |
Appends all elements from initializer list ilist
to the end of the container, ignores all values with keys already exists in the container.
other | Initializer list to append all elements from. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
|
inline |
Appends all elements from from range [first, last)
to the end of the container, ignores all values with keys already exists in the container.
first | Iterator to the first element to append from. |
last | Iterator after the last element to append from. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
|
inline |
Appends a new element to the end of the container.
Args | Arguments to forward to the constructor of the element. |
key | The key of the element to append. |
args | Arguments to forward to the constructor of value. |
bool
denoting whether the insertion took place.The element is constructed through std::allocator_traits::construct
, which typically uses placement-new to construct the element in-place at the location provided by the container. The arguments args...
are forwarded to the constructor as std::forward<Args>(args)...
.
Complexity
Logarithmic in the size of the container.
|
inline |
Appends a new element to the end of the container.
Args | Arguments to forward to the constructor of the element. |
key | The key of the element to append. |
args | Arguments to forward to the constructor of value. |
bool
denoting whether the insertion took place.The element is constructed through std::allocator_traits::construct
, which typically uses placement-new to construct the element in-place at the location provided by the container. The arguments args...
are forwarded to the constructor as std::forward<Args>(args)...
.
Complexity
Logarithmic in the size of the container.
|
inline |
Same as push_back, appends all elements from given container other
to the end of the container, ignores all values with keys already exists in the container.
other | Another container to append all elements from. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
|
inline |
Same as push_back, appends all elements from given container other
to the end of the container, ignores all values with keys already exists in the container.
other | Another container to append all elements from. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
|
inline |
Same as push_back, appends all elements from given container other
to the end of the container and return *this
, ignores all values with keys already exists in the container.
other | Another container to append all elements from. |
*this
after appends.Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
|
inline |
Same as push_back, appends all elements from given container other
to the end of the container and return *this
, ignores all values with keys already exists in the container.
other | Another container to append all elements from. |
*this
after appends.Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
|
inline |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key.
pos | Index to the position before which the new element will be inserted. |
value | Element to insert. |
Complexity
Linear in the size of the container, i.e., the number of elements.
|
inline |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key.
pos | Index to the position before which the new element will be inserted. |
value | Element to insert. |
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key.
pos | Index to the position before which the new element will be inserted. |
key | Key of element to insert. |
value | Value of element to insert. |
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key.
pos | Index to the position before which the new element will be inserted. |
key | Key of element to insert. |
value | Value of element to insert. |
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key.
pos | Iterator to the position before which the new element will be inserted. |
value | Element to insert. |
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key.
pos | Iterator to the position before which the new element will be inserted. |
value | Element to insert. |
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key.
pos | Iterator to the position before which the new element will be inserted. |
key | Key of element to insert. |
value | Value of element to insert. |
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts element into the container, if the container doesn't already contain an element with an equivalent key.
pos | Iterator to the position before which the new element will be inserted. |
key | Key of element to insert. |
value | Value of element to insert. |
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts elements into the container, if the container doesn't already contain an element with an equivalent key.
InputIt | Must meet the requirements of LegacyInputIterator. |
pos | Index to the position before which the new element will be inserted. |
first | Iterator to the first element to insert. |
last | Iterator after the last element to insert. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts elements into the container, if the container doesn't already contain an element with an equivalent key.
pos | Index to the position before which the new element will be inserted. |
ilist | Initializer list to insert the values from. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts elements into the container, if the container doesn't already contain an element with an equivalent key.
InputIt | Must meet the requirements of LegacyInputIterator. |
pos | Iterator to the position before which the new element will be inserted. |
first | Iterator to the first element to insert. |
last | Iterator after the last element to insert. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts elements into the container, if the container doesn't already contain an element with an equivalent key.
pos | Iterator to the position before which the new element will be inserted. |
ilist | Initializer list to insert the values from. |
Complexity
O(N*log(size() + N))
, where N is the number of elements to insert.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts a new element to the container as close as possible to the position just before hint. The element is constructed in-place, i.e. no copy or move operations are performed.
Args |
pos | Index to the position before which the new element will be inserted. |
key | Key of element to insert. |
args | Arguments to forward to the constructor of the value. |
The constructor of the value type (T
) is called with exactly the same arguments as supplied to the function, forwarded with std::forward<Args>(args)...
.
Invalidates iterators after pos
.
No references are invalidated.
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts a new element to the container as close as possible to the position just before hint. The element is constructed in-place, i.e. no copy or move operations are performed.
Args |
pos | Index to the position before which the new element will be inserted. |
key | Key of element to insert. |
args | Arguments to forward to the constructor of the value. |
The constructor of the value type (T
) is called with exactly the same arguments as supplied to the function, forwarded with std::forward<Args>(args)...
.
Invalidates iterators after pos
.
No references are invalidated.
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Inserts a new element to the container as close as possible to the position just before hint. The element is constructed in-place, i.e. no copy or move operations are performed.
Args |
pos | Iterator to the position before which the new element will be inserted. |
key | Key of element to insert. |
args | Arguments to forward to the constructor of the value. |
The constructor of the value type (T
) is called with exactly the same arguments as supplied to the function, forwarded with std::forward<Args>(args)...
.
Invalidates iterators after hint
.
No references are invalidated.
Complexity
Linear in the size of the container, i.e., the number of elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
|
inline |
Removes specified element from the container.
key | Key of element to erase. |
Invalidates reference to the erased element.
Invalidates iterators at or after the point of the erase.
Other references and iterators are not affected.
Complexity
Linear: the number of calls to the destructor of T is the same as the number of elements erased, the assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Removes specified elements from the container.
pos | Index to the position of the first element to erase. |
count | Elements count to erase. |
Invalidates references to the erased element.
Invalidates iterators at or after the eraseed elements.
Other references and iterators are not affected.
Complexity
Linear: the number of calls to the destructor of T is the same as the number of elements erased, the assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Removes specified elements from the container.
key | Key of element to erase. |
Invalidates reference to the erased element.
Invalidates iterators at or after the point of the erase.
Other references and iterators are not affected.
Complexity
Linear: the number of calls to the destructor of T is the same as the number of elements erased, the assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
Removes specified elements from the container.
first | Iterator to the first element to erase. |
last | Iterator after the last element to erase. |
Invalidates references to the erased element.
Invalidates iterators at or after the eraseed elements.
Other references and iterators are not affected.
Complexity
Linear: the number of calls to the destructor of T is the same as the number of elements erased, the assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements.
Much faster than raw std::vector
, because moved values are std::map::iterator
, not acture T
node.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
Returns an iterator to the first key of the container.
If the container is empty, the returned iterator will be equal to end()
.
Complexity
Constant.
|
inline |
Returns an iterator to the key following the last key of the container.
This key acts as a placeholder; attempting to access it results in undefined behavior.
Complexity
Constant.
|
inline |
Returns a reverse iterator to the first key of the reversed container. It corresponds to the last key of the non-reversed container. If the container is empty, the returned iterator is equal to rend()
.
Complexity
Constant.
|
inline |
Returns a reverse iterator to the key following the last key of the reversed container. It corresponds to the key preceding the first key of the non-reversed container. This key acts as a placeholder, attempting to access it results in undefined behavior.
Complexity
Constant.
|
inline |
Replaces the contents of the input container.
other | Another container to use as data source |
*this
.Complexity
Linear in the size of *this
and other
.
|
inline |
Replaces the contents of the input container.
other | Another container to use as data source |
*this
.Complexity
Linear in the size of *this
unless the allocators do not compare equal and do not propagate, in which case linear in the size of *this
and other
.
|
inline |
Replaces the contents of the input container.
Ilist | Initializer list to use as data source. |
*this
.Complexity
O(NlogN)
in general, where N
is size() + ilist.size()
. Linear if ilist
is sorted with respect to value_comp()
.
|
inline |
Checks if the contents of two containers are not equal.
other | Another container whose contents to compare. |
true
if the contents of the containers are equal
, false
otherwise.Equal
means that they have the same number of elements and each element in this
compares equal with the element in other
at the same position.
Complexity
Constant if containers are of different size, otherwise linear in the size of the container.
|
inline |
Checks if the contents of two containers are equal, that is,.
other | Another container whose contents to compare. |
true
if the contents of the containers are not equal
, false
otherwise.Equal
means that they have the same number of elements and each element in this
compares equal with the element in other
at the same position.
Complexity
Constant if containers are of different size, otherwise linear in the size of the container.
|
inline |
Compares the contents of two containers lexicographically.
other | Another container whose contents to compare. |
true
if the contents of this
are lexicographically less
than the contents of other
, false
otherwise.The comparison is performed by a function equivalent to std::lexicographical_compare
. This comparison ignores the container's ordering Compare.
Complexity
Linear in the size of the container.
|
inline |
Compares the contents of two containers lexicographically.
other | Another container whose contents to compare. |
true
if the contents of this
are lexicographically less
than or equal
the contents of other
, false
otherwise.The comparison is performed by a function equivalent to std::lexicographical_compare
. This comparison ignores the container's ordering Compare.
Complexity
Linear in the size of the container.
|
inline |
Compares the contents of two containers lexicographically.
other | Another container whose contents to compare. |
true
if the contents of this
are lexicographically greater
than the contents of other
, false
otherwise.The comparison is performed by a function equivalent to std::lexicographical_compare
. This comparison ignores the container's ordering Compare.
Complexity
Linear in the size of the container.
|
inline |
Compares the contents of two containers lexicographically.
other | Another container whose contents to compare. |
true
if the contents of this
are lexicographically greater
than or equal
the contents of other
, false
otherwise.The comparison is performed by a function equivalent to std::lexicographical_compare
. This comparison ignores the container's ordering Compare.
Complexity
Linear in the size of the container.
|
inline |
Exchanges the contents of the container with those of other. Does not invoke any move, copy, or swap operations on individual elements.
other | Container to exchange the contents with. |
All iterators and references remain valid. The past-the-end iterator is invalidated.
The Pred objects must be Swappable, and they are exchanged using unqualified call to non-member swap.
Complexity
Constant.
|
inline |
Returns the function object that compares the keys, which is a copy of this container's constructor argument comp.
Complexity
Constant.
|
inline |
Returns a function object that compares objects of type std::map::value_type
(key-value pairs) by using key_comp
to compare the first components of the pairs.
Complexity
Constant.
|
inline |
Serialize the contents to output stream.
Sample Code
Key
and T
.
|
inline |
Deserialize the contents from input stream.
Sample Code
Key
and T
.
|
friend |
Writes the contents of list to output stream.
Stream | Needs to support streaming type Key and T . |
out | Output stream. |
map | Map to be written to out . |
out
itself.Output format will be like:
SequencialMap(("a",0),("b",1),("c",2),("d",3),("e",4), ("f",5),("g",6),("h",7),("i",8),("k",9),...) Complexity
Linear in the size of the container, i.e., the number of elements.
|
related |
Specializes the std::swap
algorithm.
Key | Key type of input maps. |
T | Value type of input maps. |
Compare | ComparisonfFunction object to use for all comparisons of keys. |
Allocator | Allocator to use for all memory allocations of this container. |
lhs | Map whose contents to swap. |
rhs | Map whose contents to swap. |
Specializes the std::swap
algorithm for Container::SequencialMap. Swaps the maps of lhs
and rhs
. Calls lhs.swap(rhs)
.
Complexity
Constant.
|
related |
Erases all elements that satisfy the predicate pred from the container.
Key | Key type of input maps. |
T | Value type of input maps. |
Compare | ComparisonfFunction object to use for all comparisons of keys. |
Alloc | Allocator to use for all memory allocations of this container. |
Pred | Predicate that returns true if the element should be erased. |
c | Container from which to erase. |
pred | Predicate that returns true if the element should be erased. |
Complexity
Constant.