|
static itr_t | begin (container_t &container) |
| Returns an iterator to the first element of the container. More...
|
|
static const_itr_t | begin (const container_t &container) |
| Returns an iterator to the first element of the container. More...
|
|
static void | clear (container_t &container) |
| Removes all elements from the container. More...
|
|
static itr_t | end (container_t &container) |
| Returns an iterator to the element following the last element of the container. More...
|
|
static const_itr_t | end (const container_t &container) |
| Returns an iterator to the element following the last element of the container. More...
|
|
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. More...
|
|
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. More...
|
|
static std::size_t | erase (container_t &container, const key_t &key) |
| Removes the element (if one exists) with the key equivalent to key. More...
|
|
static itr_t | find (container_t &container, const key_t &key) |
| Finds an element with key equivalent to key and returns its iterator. More...
|
|
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. More...
|
|
static const key_t & | get_key (const const_itr_t &itr) |
| Returns the current iterator's key as a const reference. More...
|
|
static std::size_t | get_size (const container_t &container) |
| Returns the number of elements in the container. More...
|
|
static value_t & | get_value (itr_t &itr) |
| Returns the current iterator's value as reference. More...
|
|
static const value_t & | get_value (const const_itr_t &itr) |
| Returns the current iterator's value as const reference. More...
|
|
static std::pair< itr_t, bool > | insert_key (container_t &container, const key_t &key) |
| Inserts a key into the container. More...
|
|
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. More...
|
|
static bool | is_empty (const container_t &container) |
| Returns the number of elements in the container. More...
|
|
template<typename T>
struct rttr::associative_container_mapper< T >
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>
std::multiset<Key>
std::multimap<Key
, T>
std::unordered_set<Key>
std::unordered_map<Key
, T>
std::unordered_multiset<Key>
std::unordered_multimap<Key
, T>
Custom associative container
For a specialization of the class associative_container_mapper<T> 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;
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);
static std::pair<itr_t, bool> insert_key_value(container_t& container, const key_t& key, const value_t& value);
Following code example for the associative container QHash<K, T> illustrates how to add a specialization:
{
template<typename K, typename T>
struct associative_container_mapper<QHash<K, T>>
{
using key_t =
typename QHash<K, T>::key_type;
using value_t =
typename QHash<K, T>::mapped_type;
using itr_t =
typename QHash<K, T>::iterator;
using const_itr_t =
typename QHash<K, T>::const_iterator;
{
return itr.key();
}
{
return itr.value();
}
{
return itr.value();
}
{
return container.begin();
}
{
return container.begin();
}
static itr_t end(container_t& container)
{
return container.end();
}
{
return container.end();
}
{
return container.find(key);
}
{
return container.find(key);
}
{
auto ret = container.equal_range(key);
return std::make_pair(ret.first, ret.second);
}
static std::pair<const_itr_t, const_itr_t>
equal_range(
const container_t& container,
key_t& key)
{
auto ret = container.equal_range(key);
return std::make_pair(ret.first, ret.second);
}
static void clear(container_t& container)
{
container.clear();
}
static bool is_empty(
const container_t& container)
{
return container.isEmpty();
}
static std::size_t
get_size(
const container_t& container)
{
return container.size();
}
static std::size_t
erase(container_t& container,
key_t& key)
{
return container.remove(key);
}
{
return std::make_pair(container.insert(key, value), true);
}
};
}