Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Public Types | Public Member Functions
ext::map< T, R, Cmp, Alloc > Class Template Reference

Class extending the map class from the standard library. Original reason is to allow printing of the container with overloaded operator <<. More...

#include <map.hpp>

Inheritance diagram for ext::map< T, R, Cmp, Alloc >:
[legend]
Collaboration diagram for ext::map< T, R, Cmp, Alloc >:
[legend]

Public Types

using iterator = typename std::map< T, R, Cmp, Alloc >::iterator
 The iterator type is inheried. More...
 

Public Member Functions

 map ()=default
 
 map (const map &other)=default
 
 map (map &&other)=default
 
mapoperator= (map &&other)=default
 
mapoperator= (const map &other)=default
 
template<class Iterator >
 map (const ext::iterator_range< Iterator > &range)
 
std::pair< iterator, bool > insert (const T &key, const R &value)
 Insert variant with explicit key and value parameters. More...
 
std::pair< iterator, bool > insert (const T &key, R &&value)
 Insert variant with explicit key and value parameters. More...
 
std::pair< iterator, bool > insert (T &&key, const R &value)
 Insert variant with explicit key and value parameters. More...
 
std::pair< iterator, bool > insert (T &&key, R &&value)
 Insert variant with explicit key and value parameters. More...
 
R & at (const T &key, R &defaultValue)
 
const R & at (const T &key, const R &defaultValue) const
 
auto begin () &
 Inherited behavior of begin for non-const instance. More...
 
auto begin () const &
 Inherited behavior of begin for const instance. More...
 
auto begin () &&
 New variant of begin for rvalues. More...
 
auto end () &
 Inherited behavior of end for non-const instance. More...
 
auto end () const &
 Inherited behavior of end for const instance. More...
 
auto end () &&
 New variant of end for rvalues. More...
 
auto range () &
 Make range of non-const begin to end iterators. More...
 
auto range () const &
 Make range of non-const begin to end iterators. More...
 
auto range () &&
 Make range of move begin to end iterators. More...
 
template<class K >
auto equal_range (K &&key) const &
 Make range of elements with key equal to the key. More...
 
template<class K >
auto equal_range (K &&key) &
 Make range of elements with key equal to the key. More...
 
template<class K >
auto equal_range (K &&key) &&
 Make range of elements with key equal to the key. More...
 
template<class K >
size_t erase (const K &key)
 Erase by key of arbitrary type. More...
 
template<class K >
R & operator[] (K &&key)
 Retrieve value by key of arbitrary type. More...
 

Detailed Description

template<typename T, typename R, typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
class ext::map< T, R, Cmp, Alloc >

Class extending the map class from the standard library. Original reason is to allow printing of the container with overloaded operator <<.

The class mimics the behavior of the map from the standatd library.

Template Parameters
Tthe type of keys inside the map
Rthe type of values inside the map
Cmpthe comparator type used to order keys
Allocthe allocator of values of type T

Member Typedef Documentation

◆ iterator

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
using ext::map< T, R, Cmp, Alloc >::iterator = typename std::map<T, R, Cmp, Alloc>::iterator

The iterator type is inheried.

Constructor & Destructor Documentation

◆ map() [1/4]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
ext::map< T, R, Cmp, Alloc >::map ( )
default

Default constructor needed by g++ since it is not inherited

◆ map() [2/4]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
ext::map< T, R, Cmp, Alloc >::map ( const map< T, R, Cmp, Alloc > &  other)
default

Copy constructor needed by g++ since it is not inherited

◆ map() [3/4]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
ext::map< T, R, Cmp, Alloc >::map ( map< T, R, Cmp, Alloc > &&  other)
default

Move constructor needed by g++ since it is not inherited

◆ map() [4/4]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
template<class Iterator >
ext::map< T, R, Cmp, Alloc >::map ( const ext::iterator_range< Iterator > &  range)
inlineexplicit

Constructor from range of values.

Template Parameters
Iteratorthe type of range iterator
Parameters
rangethe source range

Member Function Documentation

◆ at() [1/2]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
const R & ext::map< T, R, Cmp, Alloc >::at ( const T &  key,
const R &  defaultValue 
) const
inline
Here is the call graph for this function:

◆ at() [2/2]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
R & ext::map< T, R, Cmp, Alloc >::at ( const T &  key,
R &  defaultValue 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [1/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::begin ( ) &
inline

Inherited behavior of begin for non-const instance.

Returns
iterator the first element of map
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [2/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::begin ( ) &&
inline

New variant of begin for rvalues.

Returns
move_iterator the first element of map
Here is the call graph for this function:

◆ begin() [3/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::begin ( ) const &
inline

Inherited behavior of begin for const instance.

Returns
const_iterator the first element of map
Here is the call graph for this function:

◆ end() [1/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::end ( ) &
inline

Inherited behavior of end for non-const instance.

Returns
iterator to one after the last element of map
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [2/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::end ( ) &&
inline

New variant of end for rvalues.

Returns
move_iterator to one after the last element of map
Here is the call graph for this function:

◆ end() [3/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::end ( ) const &
inline

Inherited behavior of end for const instance.

Returns
const_iterator to one after the last element of map
Here is the call graph for this function:

◆ equal_range() [1/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
template<class K >
auto ext::map< T, R, Cmp, Alloc >::equal_range ( K &&  key) &
inline

Make range of elements with key equal to the key.

Template Parameters
Kthe key used in the query
Parameters
keythe value used in the query
Returns
selected range of elements

◆ equal_range() [2/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
template<class K >
auto ext::map< T, R, Cmp, Alloc >::equal_range ( K &&  key) &&
inline

Make range of elements with key equal to the key.

Template Parameters
Kthe key used in the query
Parameters
keythe value used in the query
Returns
selected range of elements
Here is the call graph for this function:

◆ equal_range() [3/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
template<class K >
auto ext::map< T, R, Cmp, Alloc >::equal_range ( K &&  key) const &
inline

Make range of elements with key equal to the key.

Template Parameters
Kthe key used in the query
Parameters
keythe value used in the query
Returns
selected range of elements

◆ erase()

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
template<class K >
size_t ext::map< T, R, Cmp, Alloc >::erase ( const K &  key)
inline

Erase by key of arbitrary type.

Template Parameters
Kthe type of the key
Parameters
keythe erased key.
Returns
the number of erased elements
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [1/4]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
std::pair< iterator, bool > ext::map< T, R, Cmp, Alloc >::insert ( const T &  key,
const R &  value 
)
inline

Insert variant with explicit key and value parameters.

Parameters
keythe key
valuethe value
Returns
pair of iterator to inserted key-value pair and true if the value was inserted or false if the key already exited
Here is the call graph for this function:

◆ insert() [2/4]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
std::pair< iterator, bool > ext::map< T, R, Cmp, Alloc >::insert ( const T &  key,
R &&  value 
)
inline

Insert variant with explicit key and value parameters.

Parameters
keythe key
valuethe value
Returns
pair of iterator to inserted key-value pair and true if the value was inserted or false if the key already exited
Here is the call graph for this function:

◆ insert() [3/4]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
std::pair< iterator, bool > ext::map< T, R, Cmp, Alloc >::insert ( T &&  key,
const R &  value 
)
inline

Insert variant with explicit key and value parameters.

Parameters
keythe key
valuethe value
Returns
pair of iterator to inserted key-value pair and true if the value was inserted or false if the key already exited
Here is the call graph for this function:

◆ insert() [4/4]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
std::pair< iterator, bool > ext::map< T, R, Cmp, Alloc >::insert ( T &&  key,
R &&  value 
)
inline

Insert variant with explicit key and value parameters.

Parameters
keythe key
valuethe value
Returns
pair of iterator to inserted key-value pair and true if the value was inserted or false if the key already exited
Here is the call graph for this function:

◆ operator=() [1/2]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
map & ext::map< T, R, Cmp, Alloc >::operator= ( const map< T, R, Cmp, Alloc > &  other)
default

Move operator = needed by g++ since it is not inherited

◆ operator=() [2/2]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
map & ext::map< T, R, Cmp, Alloc >::operator= ( map< T, R, Cmp, Alloc > &&  other)
default

Copy operator = needed by g++ since it is not inherited

◆ operator[]()

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
template<class K >
R & ext::map< T, R, Cmp, Alloc >::operator[] ( K &&  key)
inline

Retrieve value by key of arbitrary type.

Template Parameters
Kthe type of the key
Parameters
keythe key of retrieved value
Returns
the mapped value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ range() [1/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::range ( ) &
inline

Make range of non-const begin to end iterators.

Returns
full range over container values
Here is the call graph for this function:

◆ range() [2/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::range ( ) &&
inline

Make range of move begin to end iterators.

Returns
full range over container values

◆ range() [3/3]

template<typename T , typename R , typename Cmp = std::less < >, typename Alloc = std::allocator < std::pair < const T, R > >>
auto ext::map< T, R, Cmp, Alloc >::range ( ) const &
inline

Make range of non-const begin to end iterators.

Returns
full range over container values
Here is the call graph for this function:

The documentation for this class was generated from the following file: