Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
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 = std::remove_reference_t<decltype(*std::declval<base_value>())>
 
using base_pointer = typename std::iterator_traits<Iter>::pointer
 
using pointer
 
using base_reference = typename std::iterator_traits<Iter>::reference
 
using reference
 
template<typename Tag , typename Iterables >
using require_t = detail_indirect::require_t<Tag, Iter>
 

Public Member Functions

constexpr IndirectIterator (Iter iterator) noexcept(std::is_nothrow_move_constructible_v< Iter >)
 
template<typename OtherIter , typename = std::enable_if_t<std::is_convertible_v<OtherIter, Iter>>>
constexpr IndirectIterator (IndirectIterator< OtherIter > iterator) noexcept(std::is_nothrow_move_constructible_v< Iter >)
 
constexpr IndirectIterator (const IndirectIterator &) noexcept(std::is_nothrow_copy_constructible_v< Iter >)=default
 
constexpr IndirectIteratoroperator= (const IndirectIterator &) noexcept(std::is_nothrow_assignable_v< Iter, Iter >)=default
 
constexpr IndirectIterator (IndirectIterator &&) noexcept(std::is_nothrow_move_constructible_v< Iter >)=default
 
constexpr IndirectIteratoroperator= (IndirectIterator &&) noexcept(std::is_nothrow_move_assignable_v< Iter >)=default
 
constexpr IndirectIteratoroperator++ ()
 
constexpr IndirectIterator operator++ (int)
 
template<typename I = Iter, typename = require_t<std::bidirectional_iterator_tag, I>>
constexpr IndirectIteratoroperator-- ()
 
template<typename I = Iter, typename = require_t<std::bidirectional_iterator_tag, I>>
constexpr IndirectIterator operator-- (int)
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr IndirectIteratoroperator+= (difference_type rhs)
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr IndirectIteratoroperator-= (difference_type rhs)
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr difference_type operator- (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr IndirectIterator operator+ (difference_type i) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr IndirectIterator operator- (difference_type i) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr reference operator[] (difference_type i) const
 
constexpr reference operator* () const
 
constexpr pointer operator-> () const
 
constexpr const Iter & base () const &
 
constexpr Iter & base () &
 
constexpr Iter base () &&
 
constexpr bool operator== (const IndirectIterator &rhs) const
 
constexpr bool operator!= (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr bool operator> (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr bool operator< (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr bool operator>= (const IndirectIterator &rhs) const
 
template<typename I = Iter, typename = require_t<std::random_access_iterator_tag, I>>
constexpr 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
IndirectIterator< Iter, PropagateConst > makeIndirectIterator(Iter iter) noexcept(std::is_nothrow_move_constructible_v< Iter >)
Definition indirectiterator.h:271

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 Typedef Documentation

◆ pointer

template<typename Iter , bool PropagateConst = true>
using inviwo::util::IndirectIterator< Iter, PropagateConst >::pointer
Initial value:
decltype(detail_indirect::asPointer<is_const>::get(*std::declval<base_pointer>()))

◆ reference

template<typename Iter , bool PropagateConst = true>
using inviwo::util::IndirectIterator< Iter, PropagateConst >::reference
Initial value:
std::conditional_t<
is_const,
detail_indirect::add_const_to_reference_t<decltype(*std::declval<base_reference>())>,
decltype(*std::declval<base_reference>())>

Member Data Documentation

◆ is_const

template<typename Iter , bool PropagateConst = true>
bool inviwo::util::IndirectIterator< Iter, PropagateConst >::is_const
staticconstexpr
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: