Inviwo  0.9.10.1
Inviwo documentation
inviwo::util::IndirectIterator< Iter, PropagateConst > Struct Template Reference

#include <indirectiterator.h>

Public Types

using difference_type = typename std::iterator_traits< Iter >::difference_type
 
using iterator_category = typename std::iterator_traits< Iter >::iterator_category
 
using base_value = typename std::iterator_traits< Iter >::value_type
 
using value_type = decltype(*std::declval< base_value >())
 
using base_pointer = typename std::iterator_traits< Iter >::pointer
 
using pointer = decltype(detail_indirect::asPointer< is_const >::get(*std::declval< base_pointer >()))
 
using base_reference = typename std::iterator_traits< Iter >::reference
 
using reference = std::conditional_t< is_const, detail_indirect::add_const_to_reference_t< decltype(*std::declval< base_reference >())>, decltype(*std::declval< base_reference >())>
 
template<typename Tag , typename Iterables >
using require_t = detail_indirect::require_t< Tag, Iter >
 

Public Member Functions

 IndirectIterator (Iter iterator)
 
IndirectIteratoroperator++ ()
 
IndirectIterator operator++ (int)
 
template<typename I = Iter, typename = require_t<std::bidirectional_iterator_tag, I>>
IndirectIteratoroperator-- ()
 
template<typename I = Iter, typename = require_t<std::bidirectional_iterator_tag, I>>
IndirectIterator operator-- (int)
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
IndirectIteratoroperator+= (difference_type rhs)
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
IndirectIteratoroperator-= (difference_type rhs)
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
difference_type operator- (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
IndirectIterator operator+ (difference_type i) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
IndirectIterator operator- (difference_type i) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
reference operator[] (difference_type i) const
 
reference operator * () const
 
pointer operator-> () const
 
const Iter & base () const
 
Iter & base ()
 
bool operator== (const IndirectIterator &rhs) const
 
bool operator!= (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
bool operator> (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
bool operator< (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
bool operator>= (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
bool operator<= (const IndirectIterator &rhs) const
 

Static Public Attributes

static constexpr bool is_const
 

Detailed Description

template<typename Iter, bool PropagateConst = true>
struct inviwo::util::IndirectIterator< Iter, PropagateConst >

IndirectIterator<typename Iter, bool PropagateConst = true> Iter is underlying iterator to a pointer like type PropagateConst decides if we should treat the value as const if the pointer is const.

Example:

std::vector<std::unique_ptr<int>> vec;
for (int i = 0; i < 5; ++i) {
vec.push_back(std::make_unique<int>(i));
}
auto it = util::makeIndirectIterator(vec.begin());
*it = 5; // *it is a int& not a std::make_unique<int>&
// note cbegin() return a const_iterator
auto const_it = util::makeIndirectIterator<true>(vec.cbegin());
*const_it = 5; // will fail since we propagate const from the pointer to the value
auto mutable_it = util::makeIndirectIterator<false>(vec.cbegin());
*mutable_it = 5; // will work since __don't__ propagate const from the pointer to the value

The use case is to container types that stores items using a vector of pointers, but want to expose an iterator directly to the item not to the pointer.

See also
makeIndirectIterator

Member Data Documentation

◆ is_const

template<typename Iter , bool PropagateConst = true>
constexpr bool inviwo::util::IndirectIterator< Iter, PropagateConst >::is_const
static
Initial value:
=
std::conditional_t<PropagateConst, detail_indirect::is_const_iterator<Iter>,
std::false_type>::value

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