The variant_associative_view describes a class that refers to an associative container (e.g: std::map
) inside a variant.
More...
#include <variant_associative_view.h>
Classes | |
class | const_iterator |
The variant_associative_view::const_iterator allows iteration over an associative container in a variant. More... | |
Public Member Functions | |
variant_associative_view () | |
Constructs an invalid variant_associative_view object. More... | |
variant_associative_view (const variant_associative_view &other) | |
Constructs a copy of the given variant_associative_view other . More... | |
~variant_associative_view () noexcept | |
Destroys the variant_associative_view. More... | |
const_iterator | begin () const |
Returns an iterator to the first element of the container. More... | |
void | clear () |
Removes all elements from the container. More... | |
const_iterator | end () const |
Returns an iterator to the element following the last element of the container. More... | |
std::pair< const_iterator, const_iterator > | equal_range (argument key) |
Returns a range containing all elements with the given key in the container. More... | |
std::size_t | erase (argument key) |
Removes the element (if one exists) with the key equivalent to key . More... | |
const_iterator | find (argument key) |
Finds an element with specific key key . More... | |
type | get_key_type () const noexcept |
Returns the type from the key of this associative container. More... | |
std::size_t | get_size () const noexcept |
Returns the number of elements in the associative container. More... | |
type | get_type () const noexcept |
Returns the type object of this associative container. More... | |
type | get_value_type () const noexcept |
Returns the type object from the value of this associative container. More... | |
std::pair< const_iterator, bool > | insert (argument key) |
Insert a key into the container. More... | |
std::pair< const_iterator, bool > | insert (argument key, argument value) |
Insert a key-value pair into the container. More... | |
bool | is_empty () const noexcept |
Checks if the container has no elements. More... | |
bool | is_key_only_type () const noexcept |
Returns true , when this associative container stores only keys. More... | |
bool | is_valid () const noexcept |
Returns true if this variant_associative_view is valid, that means the object is holding some data. More... | |
operator bool () const noexcept | |
Convenience function to check if this variant_associative_view is valid or not. More... | |
variant_associative_view & | operator= (const variant_associative_view &other) noexcept |
Assigns the value of the other variant_associative_view to this variant_associative_view. More... | |
void | swap (variant_associative_view &other) noexcept |
Swaps this variant_associative_view with the other variant_associative_view. More... | |
Detailed Description
The variant_associative_view describes a class that refers to an associative container (e.g: std::map
) inside a variant.
With an instance of that class you can set/get values of such container, without having access to the type declaration of the type or it's elements.
A variant_associative_view can be created directly from a variant with its member function create_associative_view().
- Remarks
- The instance of an variant_associative_view is always valid as long as the referenced variant is valid, otherwise accessing a variant_associative_view is undefined behaviour.
Meta Information
RTTR recognize whether a type is an associative container or not with the help of the associative_container_mapper class template. This call can access different container types via one common interface. At the moment there exist specializations for following 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>
and std::unordered_multimap<Key, T>
.
Copying and Assignment
A variant_associative_view object can be copied and assigned, however each copy will reference the data of same underlying variant value.
Typical Usage
- See also
- variant
Constructor & Destructor Documentation
rttr::variant_associative_view::variant_associative_view | ( | ) |
Constructs an invalid variant_associative_view object.
- See also
- is_valid()
rttr::variant_associative_view::variant_associative_view | ( | const variant_associative_view & | other | ) |
Constructs a copy of the given variant_associative_view other
.
|
noexcept |
Destroys the variant_associative_view.
- Remarks
- The underlying data is not destroyed.
Member Function Documentation
const_iterator rttr::variant_associative_view::begin | ( | ) | const |
Returns an iterator to the first element of the container.
- See also
- end()
- Returns
- Iterator to the first element .
void rttr::variant_associative_view::clear | ( | ) |
Removes all elements from the container.
- Remarks
- Invalidates all references, pointers, or iterators referring to contained elements.
const_iterator rttr::variant_associative_view::end | ( | ) | const |
Returns an iterator to the element following the last element of the container.
- See also
- begin()
- Returns
- Iterator to the element following the last element.
std::pair<const_iterator, const_iterator> rttr::variant_associative_view::equal_range | ( | argument | key | ) |
Returns a range containing all elements with the given key
in the container.
Example code:
Output:
- Returns
- std::pair containing a pair of iterators defining the wanted range: the first pointing to the first element that is not less than
key
and the second pointing to the first element greater thankey
.
std::size_t rttr::variant_associative_view::erase | ( | argument | key | ) |
Removes the element (if one exists) with the key equivalent to key
.
- Returns
- The number of elements removed.
const_iterator rttr::variant_associative_view::find | ( | argument | key | ) |
Finds an element with specific key key
.
- Returns
- The element with key equivalent to
key
. If no element is found an invalid iterator is returned.
|
noexcept |
|
noexcept |
Returns the number of elements in the associative container.
- Returns
- The number of elements in the associative container.
|
noexcept |
|
noexcept |
std::pair<const_iterator, bool> rttr::variant_associative_view::insert | ( | argument | key | ) |
Insert a key into the container.
- Returns
- A pair consisting of an iterator to the inserted element (or to the element that prevented the insertion) and a bool denoting whether the insertion took place.
std::pair<const_iterator, bool> rttr::variant_associative_view::insert | ( | argument | key, |
argument | value | ||
) |
Insert a key-value pair into the container.
- Returns
- A pair consisting of an iterator to the inserted element (or to the element that prevented the insertion) and a bool denoting whether the insertion took place.
|
noexcept |
Checks if the container has no elements.
- Returns
true
if container is empty, otherwisefalse
.
|
noexcept |
Returns true
, when this associative container stores only keys.
When also value are stored, it will return false
.
For example an std::set
has no values, it's a key-only associative container. Then this method returns true
. An std::map<K,V>
on the other hand contains keys and values. So this method will then return false
. A simple convenience method instead of calling: get_value_type().is_valid() == false;
- Returns
true
, when this associative container stores only keys; otherwisefalse
.
|
noexcept |
Returns true if this variant_associative_view is valid, that means the object is holding some data.
When the variant_associative_view doesn't hold any data it will return false.
- Returns
- True if this variant_associative_view is valid, otherwise false.
|
explicitnoexcept |
Convenience function to check if this variant_associative_view is valid or not.
- See also
- is_valid()
- Returns
- True if this variant_associative_view is valid, otherwise false.
|
noexcept |
Assigns the value of the other variant_associative_view to this variant_associative_view.
- Returns
- A reference to the variant_associative_view with the new data.
|
noexcept |
Swaps this variant_associative_view with the other variant_associative_view.
The documentation for this class was generated from the following file: