The variant_sequential_view describes a class that refers to an sequence container (e.g: std::vector) inside a variant. More...
#include <variant_sequential_view.h>
Classes | |
class | const_iterator |
The variant_sequential_view::const_iterator allows iteration over an sequential container in a variant. More... |
Public Member Functions | |
variant_sequential_view () | |
Constructs an invalid variant_sequential_view object. | |
variant_sequential_view (const variant_sequential_view &other) | |
Constructs a copy of the given variant_sequential_view other . | |
~variant_sequential_view () noexcept | |
Destroys the variant_sequential_view. | |
const_iterator | begin () const |
Returns an iterator to the first element of the container. | |
void | clear () |
Removes all elements from the container. | |
const_iterator | end () const |
Returns an iterator to the element following the last element of the container. | |
const_iterator | erase (const const_iterator &pos) |
Removes the element (if one exists) at the position pos . | |
std::size_t | get_rank () const noexcept |
Gets the rank (number of dimensions) of this sequential container. | |
type | get_rank_type (std::size_t index) const noexcept |
Gets the type of the given rank index. | |
std::size_t | get_size () const noexcept |
Returns the number of elements in the sequential container. | |
type | get_type () const noexcept |
Returns the type object of this sequential container. | |
variant | get_value (std::size_t index) const |
Returns the current value at index index . | |
type | get_value_type () const noexcept |
Returns the type object from the value of this sequential container. | |
const_iterator | insert (const const_iterator &pos, argument value) |
Insert a value into the container. | |
bool | is_dynamic () const noexcept |
Returns true if this sequential view is dynamic, otherwise false. | |
bool | is_empty () const noexcept |
Checks if the container has no elements. | |
bool | is_valid () const noexcept |
Returns true if this variant_sequential_view is valid, that means the object is holding some data. | |
operator bool () const noexcept | |
Convenience function to check if this variant_sequential_view is valid or not. | |
variant_sequential_view & | operator= (const variant_sequential_view &other) noexcept |
Assigns the value of the other variant_sequential_view to this variant_sequential_view. | |
bool | set_size (std::size_t size) const noexcept |
Sets the size of the sequential container. | |
bool | set_value (std::size_t index, argument arg) |
Set the content of the the argument arg at the specified index index into the underlying sequential container. | |
void | swap (variant_sequential_view &other) noexcept |
Swaps this variant_sequential_view with the other variant_sequential_view. |
Detailed Description
The variant_sequential_view describes a class that refers to an sequence container (e.g: std::vector) 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_sequential_view can be created directly from a variant with its member function create_sequential_view().
- Remarks
- The instance of an variant_sequential_view is always valid as long as the referenced variant is valid, otherwise accessing a variant_sequential_view is undefined behaviour.
Meta Information
RTTR recognize whether a type is an sequential container or not with the help of the sequential_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::vector<T>, std::array<T, std::size_t>, std::list<T>, std::deque<T>, std::initializer_list<T> and raw arrays
Copying and Assignment
A variant_sequential_view object can be copied and assigned, however each copy will reference the data of same underlying variant value.
Typical Usage
Output:
- See also
- variant, type::is_sequential_container()
Constructor & Destructor Documentation
◆ variant_sequential_view() [1/2]
rttr::variant_sequential_view::variant_sequential_view | ( | ) |
Constructs an invalid variant_sequential_view object.
- See also
- is_valid()
◆ variant_sequential_view() [2/2]
rttr::variant_sequential_view::variant_sequential_view | ( | const variant_sequential_view & | other | ) |
Constructs a copy of the given variant_sequential_view other
.
◆ ~variant_sequential_view()
|
noexcept |
Destroys the variant_sequential_view.
- Remarks
- The underlying data is not destroyed.
Member Function Documentation
◆ begin()
const_iterator rttr::variant_sequential_view::begin | ( | ) | const |
Returns an iterator to the first element of the container.
- See also
- end()
- Returns
- Iterator to the first element .
◆ clear()
void rttr::variant_sequential_view::clear | ( | ) |
Removes all elements from the container.
- Remarks
- Invalidates all references, pointers, or iterators referring to contained elements.
◆ end()
const_iterator rttr::variant_sequential_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.
◆ erase()
const_iterator rttr::variant_sequential_view::erase | ( | const const_iterator & | pos | ) |
Removes the element (if one exists) at the position pos
.
- Returns
- Iterator following the last removed element.
◆ get_rank()
|
noexcept |
Gets the rank (number of dimensions) of this sequential container.
Take a look at following return values:
`int
[4]` => 1`int
[4][4]` => 2`int
[4][4][4]` => 3- ...
- Returns
- Returns the rank of the sequential container.
◆ get_rank_type()
|
noexcept |
Gets the type of the given rank index.
Take a look at following return value for an array of type: int[2][10]
`get_rank_type
(0)` => int[2][10]`get_rank_type
(1)` => int[10]`get_rank_type
(2)` => int`get_rank_type
(3)` => INVALID
- Returns
- The rank type at the given dimension
index
.
◆ get_size()
|
noexcept |
Returns the number of elements in the sequential container.
- Returns
- The number of elements in the sequential container.
◆ get_type()
|
noexcept |
◆ get_value()
variant rttr::variant_sequential_view::get_value | ( | std::size_t | index | ) | const |
Returns the current value at index index
.
- Returns
- The data at the specified index
index
, wrapped inside a std::reference_wrapper<T>.
- Remarks
- Make sure the index is in a valid range, otherwise undefined behaviour may occurr. For MSVC 2013 and raw arrays, the address of the data is returned (because of a bug).
- See also
- get_size()
◆ get_value_type()
|
noexcept |
◆ insert()
const_iterator rttr::variant_sequential_view::insert | ( | const const_iterator & | pos, |
argument | value ) |
Insert a value into the container.
- Returns
- An iterator to the inserted element, otherwise an invalid iterator, when the insertion was not possible.
◆ is_dynamic()
|
noexcept |
Returns true if this sequential view is dynamic, otherwise false.
When an sequential view is dynamic, it is possible to change its size, clear its content or insert and erase values from it.
- See also
- set_size(), insert(), erase(), clear()
- Returns
- A boolean flag which indicates whether this sequential container is dynamic or not.
◆ is_empty()
|
noexcept |
Checks if the container has no elements.
- Returns
- true if container is empty, otherwise false.
◆ is_valid()
|
noexcept |
Returns true if this variant_sequential_view is valid, that means the object is holding some data.
When the variant_sequential_view doesn't hold any data it will return false.
- Returns
- True if this variant_sequential_view is valid, otherwise false.
◆ operator bool()
|
explicitnoexcept |
Convenience function to check if this variant_sequential_view is valid or not.
- See also
- is_valid()
- Returns
- True if this variant_sequential_view is valid, otherwise false.
◆ operator=()
|
noexcept |
Assigns the value of the other variant_sequential_view to this variant_sequential_view.
- Returns
- A reference to the variant_sequential_view with the new data.
◆ set_size()
|
noexcept |
Sets the size of the sequential container.
- Returns
- true, when the size of the container could be changed, otherwise false.
- See also
- is_dynamic()
◆ set_value()
bool rttr::variant_sequential_view::set_value | ( | std::size_t | index, |
argument | arg ) |
Set the content of the the argument arg
at the specified index index
into the underlying sequential container.
- Returns
- true if the value could be set, otherwise false.
◆ swap()
|
noexcept |
Swaps this variant_sequential_view with the other variant_sequential_view.
The documentation for this class was generated from the following file:
Generated on Thu Jul 3 2025 04:49:14 for rttr - 0.9.6 by doxygen.