SpECTRE  v2024.05.11
stl_boilerplate::RandomAccessIterator< Iter, ValueType > Class Template Reference

Base class to generate methods for a random-access iterator. This class takes the derived class and the (optionally const) value_type of the iterator. The exposed value_type alias will always be non-const, as required by the standard, but the template parameter's constness will affect the reference and pointer aliases. More...

#include <StlBoilerplate.hpp>

Public Types

using iterator_category = std::random_access_iterator_tag
 
using value_type = std::remove_const_t< ValueType >
 
using reference = ValueType &
 
using pointer = ValueType *
 
using difference_type = std::ptrdiff_t
 

Public Member Functions

pointer operator-> () const
 
Iter & operator++ ()
 
Iter operator++ (int)
 
Iter & operator-- ()
 
Iter operator-- (int)
 
Iter & operator-= (const difference_type n)
 
reference operator[] (const difference_type n) const
 

Protected Member Functions

 RandomAccessIterator (const RandomAccessIterator &)=default
 
 RandomAccessIterator (RandomAccessIterator &&)=default
 
RandomAccessIteratoroperator= (const RandomAccessIterator &)=default
 
RandomAccessIteratoroperator= (RandomAccessIterator &&)=default
 

Detailed Description

template<typename Iter, typename ValueType>
class stl_boilerplate::RandomAccessIterator< Iter, ValueType >

Base class to generate methods for a random-access iterator. This class takes the derived class and the (optionally const) value_type of the iterator. The exposed value_type alias will always be non-const, as required by the standard, but the template parameter's constness will affect the reference and pointer aliases.

The derived class must implement operator*, operator+=, operator- (of two iterators), and operator==.

template <typename T>
class EmptyIterator
: public stl_boilerplate::RandomAccessIterator<EmptyIterator<T>, T> {
public:
T& operator*() const { ERROR("Not dereferenceable."); }
EmptyIterator& operator+=(const std::ptrdiff_t /*n*/) { return *this; }
};
// Often these will be friend functions.
template <typename T>
bool operator==(const EmptyIterator<T>& /*a*/, const EmptyIterator<T>& /*b*/) {
return true;
}
template <typename T>
std::ptrdiff_t operator-(const EmptyIterator<T>& /*a*/,
const EmptyIterator<T>& /*b*/) {
return 0;
}
Base class to generate methods for a random-access iterator. This class takes the derived class and t...
Definition: StlBoilerplate.hpp:35
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:66
auto operator*(const TensorExpression< T1, typename T1::type, typename T1::symmetry, typename T1::index_list, ArgsList1 > &t1, const TensorExpression< T2, typename T2::type, typename T2::symmetry, typename T2::index_list, ArgsList2 > &t2)
Returns the tensor expression representing the product of two tensor expressions.
Definition: Product.hpp:459

This class is inspired by Boost's iterator_facade, except that that has a lot of special cases, some of which work poorly because they predate C++11.


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