The associative_container_mapper class is a class template to access an associative container via one common interface. More...
#include <associative_mapper.h>
Public Types | |
using | const_itr_t = typename T::const_iterator |
An alias delcaration to the const iterator. | |
using | container_t = T |
An alias declaration to the container type itself. | |
using | itr_t = typename T::iterator |
An alias delcaration to the iterator. | |
using | key_t = typename T::key_type |
An alias to the key type. | |
using | value_t = typename T::mapped_type |
Static Public Member Functions | |
static const_itr_t | begin (const container_t &container) |
Returns an iterator to the first element of the container. | |
static itr_t | begin (container_t &container) |
Returns an iterator to the first element of the container. | |
static void | clear (container_t &container) |
Removes all elements from the container. | |
static const_itr_t | end (const container_t &container) |
Returns an iterator to the element following the last element of the container. | |
static itr_t | end (container_t &container) |
Returns an iterator to the element following the last element of the container. | |
static std::pair< const_itr_t, const_itr_t > | equal_range (const container_t &container, const key_t &key) |
Returns a range containing all elements with the given key in the container. | |
static std::pair< itr_t, itr_t > | equal_range (container_t &container, const key_t &key) |
Returns a range containing all elements with the given key in the container. | |
static std::size_t | erase (container_t &container, const key_t &key) |
Removes the element (if one exists) with the key equivalent to key. | |
static const_itr_t | find (const container_t &container, const key_t &key) |
Finds an element with key equivalent to key and returns its iterator. | |
static itr_t | find (container_t &container, const key_t &key) |
Finds an element with key equivalent to key and returns its iterator. | |
static const key_t & | get_key (const const_itr_t &itr) |
Returns the current iterator's key as a const reference. | |
static std::size_t | get_size (const container_t &container) |
Returns the number of elements in the container. | |
static const value_t & | get_value (const const_itr_t &itr) |
Returns the current iterator's value as const reference. | |
static value_t & | get_value (itr_t &itr) |
Returns the current iterator's value as reference. | |
static std::pair< itr_t, bool > | insert_key (container_t &container, const key_t &key) |
Inserts a key into the container. | |
static std::pair< itr_t, bool > | insert_key_value (container_t &container, const key_t &key, const value_t &value) |
Inserts a key-value into the container. | |
static bool | is_empty (const container_t &container) |
Returns the number of elements in the container. | |
Detailed Description
The associative_container_mapper class is a class template to access an associative container via one common interface.
This class will be only used internally by RTTR via the variant_associative_view class to get access to elements of an associative container. In order to use your own custom associative container type, you have to provide a specialization of this class.
Out of the box, RTTR has specialization for following associative container types:
`std::set<Key>`
`std::map<Key, T>
\p
std::multiset<Key>\p
std::multimap<Key, T>\p
std::unordered_set<Key>\p
std::unordered_map<Key, T>\p
std::unordered_multiset<Key>\p
std::unordered_multimap<Key, T>`
Custom associative container
For a specialization of the class associative_container_mapper you have to provide some nested alias templates:
using container_t = T;
using key_t = typename T::key_type;
using value_t = typename T::mapped_type;
- Remarks
- When you have a key-only container, like
std::set<T>
, usevoid
; i.e.using value_t = void;
using itr_t = typename T::iterator;
using const_itr_t = typename T::const_iterator;
and following member functions:
static const key_t& get_key(const const_itr_t& itr);
static value_t& get_value(itr_t& itr);
static const value_t& get_value(const const_itr_t& itr);
static itr_t begin(container_t& container);
static const_itr_t begin(const container_t& container);
static const_itr_t end(const container_t& container);
static itr_t find(container_t& container, const key_t& key);
static const_itr_t find(const container_t& container, const key_t& key);
static std::pair<itr_t, itr_t> equal_range(container_t& container, const key_t& key);
static std::pair<const_itr_t, const_itr_t> equal_range(const container_t& container, const key_t& key);
static void clear(container_t& container);
static bool is_empty(const container_t& container);
static std::size_t get_size(const container_t& container);
static std::size_t erase(container_t& container, const key_t& key);
static std::pair<itr_t, bool> insert_key(container_t& container, const key_t& key);
- Remarks
- This method needs to be implemented only when you have a key-only container.
static std::pair<itr_t, bool> insert_key_value(container_t& container, const key_t& key, const value_t& value);
- Remarks
- This method needs to be implemented only when you have a key-value container.
- Remarks
- Make sure you put your specialization inside the namespace
rttr
. The best place for this code, is below the declaration of your custom associative container type. When this is not possible, include your specialization code before registering your types to RTTR.
Member Typedef Documentation
◆ const_itr_t
using rttr::associative_container_mapper< T >::const_itr_t = typename T::const_iterator |
An alias delcaration to the const iterator.
◆ container_t
An alias declaration to the container type itself.
◆ itr_t
An alias delcaration to the iterator.
◆ key_t
An alias to the key type.
◆ value_t
using rttr::associative_container_mapper< T >::value_t = typename T::mapped_type |
An alias to the value type.
- Remarks
- When you have a key only container use
void
as value type. Then you also dont need to add a insert_key_value() function
Member Function Documentation
◆ begin() [1/2]
|
inlinestatic |
Returns an iterator to the first element of the container.
◆ begin() [2/2]
|
inlinestatic |
Returns an iterator to the first element of the container.
◆ clear()
|
inlinestatic |
Removes all elements from the container.
◆ end() [1/2]
|
inlinestatic |
Returns an iterator to the element following the last element of the container.
◆ end() [2/2]
|
inlinestatic |
Returns an iterator to the element following the last element of the container.
◆ equal_range() [1/2]
|
inlinestatic |
Returns a range containing all elements with the given key in the container.
The range is defined by two constant iterators, one pointing to the first element that is not less than key and another pointing to the first element greater than key.
◆ equal_range() [2/2]
|
inlinestatic |
Returns a range containing all elements with the given key in the container.
The range is defined by two iterators, one pointing to the first element that is not less than key and another pointing to the first element greater than key.
◆ erase()
|
inlinestatic |
Removes the element (if one exists) with the key equivalent to key.
◆ find() [1/2]
|
inlinestatic |
Finds an element with key equivalent to key and returns its iterator.
◆ find() [2/2]
|
inlinestatic |
Finds an element with key equivalent to key and returns its iterator.
◆ get_key()
|
inlinestatic |
Returns the current iterator's key as a const reference.
◆ get_size()
|
inlinestatic |
Returns the number of elements in the container.
◆ get_value() [1/2]
|
inlinestatic |
Returns the current iterator's value as const reference.
◆ get_value() [2/2]
|
inlinestatic |
Returns the current iterator's value as reference.
◆ insert_key()
|
inlinestatic |
Inserts a key into the container.
- Remarks
- This method is only necessary, when you have a key-only container. Like
std::set<T>
. Otherwise you don't need to declare it.
◆ insert_key_value()
|
inlinestatic |
Inserts a key-value into the container.
- Remarks
- This method is only necessary, when you have a key-value container. Like
std::map<T>
. Otherwise you don't need to declare it.
◆ is_empty()
|
inlinestatic |
Returns the number of elements in the container.
The documentation for this struct was generated from the following file:
Generated on Fri Jan 26 2024 00:00:00 for rttr - 0.9.7 by doxygen.