rttr::variant_sequential_view::const_iterator Class Reference

The variant_sequential_view::const_iterator allows iteration over an sequential container in a variant. More...

#include <variant_sequential_view.h>

Public Types

using self_type = const_iterator
 
using value_type = variant
 

Public Member Functions

 const_iterator (const const_iterator &other)
 Creates a copy of other. More...
 
 ~const_iterator ()
 Destroys the variant_sequential_view::const_iterator. More...
 
const variant get_data () const
 Returns the current value, stored inside a std::reference_wrapper<T> and copied to a variant. More...
 
bool operator!= (const const_iterator &other) const
 Returns true if other points to a different item than this iterator; otherwise returns false. More...
 
const variant operator* () const
 Returns the underlying value in a variant stored in a std::reference_wrapper<T>. More...
 
const_iterator operator+ (int i) const
 Returns an iterator to the item at i positions forward from this iterator. More...
 
const_iteratoroperator++ ()
 Pre-increment operator advances the iterator to the next item in the container and returns an iterator to the new current item. More...
 
const_iterator operator++ (int)
 Post-increment operator advances the iterator to the next item in the container and returns an iterator to the previously current item. More...
 
const_iteratoroperator+= (int i)
 Advances the iterator by i items. More...
 
const_iterator operator- (int i) const
 Returns an iterator to the item at i positions backward from this iterator. More...
 
const_iteratoroperator-- ()
 Pre-decrement operator makes the preceding item current and returns an iterator to the new current item. More...
 
const_iterator operator-- (int)
 Post-decrement operator makes the preceding item current and returns an iterator to the previously current item. More...
 
const_iteratoroperator-= (int i)
 Returns an iterator to the item at i positions backward from this iterator. More...
 
const_iteratoroperator= (const_iterator other)
 Assigns other to this. More...
 
bool operator== (const const_iterator &other) const
 Returns true if other points to the same item as this iterator; otherwise returns false. More...
 

Detailed Description

The variant_sequential_view::const_iterator allows iteration over an sequential container in a variant.

An instance can only be created by an variant_sequential_view.

Typical Usage

std::vector<int> my_vec = { 1, 2, 3, 4, 5};
variant var = my_vec; // copies data into variant
if (var.is_sequential_container())
{
variant_sequential_view view = var.create_sequential_view(); // performs no copy of the underlying vector
std::cout << view.get_size() << std::endl; // prints: '5'
for (const auto& item : view)
{
// remark that the value is stored inside a 'std::reference_wrapper', however there is an automatic conversion for wrapper classes implemented.
std::cout << "data: " << item.to_string() << " ";
}
}
Remarks
The iterator is valid as long as the variant_sequential_view and it corresponding variant is valid and not modified.

Member Typedef Documentation

Constructor & Destructor Documentation

rttr::variant_sequential_view::const_iterator::~const_iterator ( )
rttr::variant_sequential_view::const_iterator::const_iterator ( const const_iterator other)

Creates a copy of other.

Member Function Documentation

const variant rttr::variant_sequential_view::const_iterator::get_data ( ) const

Returns the current value, stored inside a std::reference_wrapper<T> and copied to a variant.

See also
operator*(), variant::extract_wrapped_value(), variant::get_wrapped_value<T>()
bool rttr::variant_sequential_view::const_iterator::operator!= ( const const_iterator other) const

Returns true if other points to a different item than this iterator; otherwise returns false.

See also
operator==
const variant rttr::variant_sequential_view::const_iterator::operator* ( ) const

Returns the underlying value in a variant stored in a std::reference_wrapper<T>.

When the data cannot be returns as reference from the container, the data is stored directly inside the variant. E.g. for std::vector<bool> no reference can be returned.

Remarks
For MSVC 2013, the return of std::reference_wrapper for arrays doesnt work, thats why we return a ptr instead.
See also
variant::extract_wrapped_value(), variant::get_wrapped_value<T>()
const_iterator rttr::variant_sequential_view::const_iterator::operator+ ( int  i) const

Returns an iterator to the item at i positions forward from this iterator.

const_iterator& rttr::variant_sequential_view::const_iterator::operator++ ( )

Pre-increment operator advances the iterator to the next item in the container and returns an iterator to the new current item.

Remarks
Calling this function on and iterator with value variant_sequential_view::end() leads to undefined behaviour.
const_iterator rttr::variant_sequential_view::const_iterator::operator++ ( int  )

Post-increment operator advances the iterator to the next item in the container and returns an iterator to the previously current item.

const_iterator& rttr::variant_sequential_view::const_iterator::operator+= ( int  i)

Advances the iterator by i items.

const_iterator rttr::variant_sequential_view::const_iterator::operator- ( int  i) const

Returns an iterator to the item at i positions backward from this iterator.

const_iterator& rttr::variant_sequential_view::const_iterator::operator-- ( )

Pre-decrement operator makes the preceding item current and returns an iterator to the new current item.

Remarks
Calling this function on and iterator with value variant_sequential_view::begin() leads to undefined behaviour.
const_iterator rttr::variant_sequential_view::const_iterator::operator-- ( int  )

Post-decrement operator makes the preceding item current and returns an iterator to the previously current item.

const_iterator& rttr::variant_sequential_view::const_iterator::operator-= ( int  i)

Returns an iterator to the item at i positions backward from this iterator.

const_iterator& rttr::variant_sequential_view::const_iterator::operator= ( const_iterator  other)

Assigns other to this.

bool rttr::variant_sequential_view::const_iterator::operator== ( const const_iterator other) const

Returns true if other points to the same item as this iterator; otherwise returns false.

See also
operator!=

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