LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT > Class Template Reference

CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of the interface. More...

#include <iterators.hpp>

Inheritance diagram for LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >:

Public Types

using iterator_category = IteratorCategoryT
 
using value_type = T
 
using difference_type = DifferenceTypeT
 
using pointer = PointerT
 
using reference = ReferenceT
 

Public Member Functions

DerivedT operator+ (DifferenceTypeT n) const
 
DerivedT operator- (DifferenceTypeT n) const
 
DerivedT & operator++ ()
 
DerivedT operator++ (int)
 
DerivedT & operator-- ()
 
DerivedT operator-- (int)
 
bool operator!= (const DerivedT &RHS) const
 
bool operator> (const DerivedT &RHS) const
 
bool operator<= (const DerivedT &RHS) const
 
bool operator>= (const DerivedT &RHS) const
 
PointerProxy operator-> () const
 
ReferenceProxy operator[] (DifferenceTypeT n) const
 

Detailed Description

template<typename DerivedT, typename IteratorCategoryT, typename T, typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
class LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >

CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of the interface.

Use this when it is reasonable to implement most of the iterator functionality in terms of a core subset. If you need special behavior or there are performance implications for this, you may want to override the relevant members instead.

Note, one abstraction that this does not provide is implementing subtraction in terms of addition by negating the difference. Negation isn't always information preserving, and I can see very reasonable iterator designs where this doesn't work well. It doesn't really force much added boilerplate anyways.

Another abstraction that this doesn't provide is implementing increment in terms of addition of one. These aren't equivalent for all iterator categories, and respecting that adds a lot of complexity for little gain.

Iterators are expected to have const rules analogous to pointers, with a single, const-qualified operator*() that returns ReferenceT. This matches the second and third pointers in the following example:

int Value;
{ int *I = &Value; } // ReferenceT 'int&'
{ int *const I = &Value; } // ReferenceT 'int&'; const
{ const int *I = &Value; } // ReferenceT 'const int&'
{ const int *const I = &Value; } // ReferenceT 'const int&'; const

If an iterator facade returns a handle to its own state, then T (and PointerT and ReferenceT) should usually be const-qualified. Otherwise, if clients are expected to modify the handle itself, the field can be declared mutable or use const_cast.

Classes wishing to use iterator_facade_base should implement the following methods:

Forward Iterators: (All of the following methods)

  • DerivedT &operator=(const DerivedT &R);
  • bool operator==(const DerivedT &R) const;
  • T &operator*() const;
  • DerivedT &operator++();

Bidirectional Iterators: (All methods of forward iterators, plus the following)

Random-access Iterators: (All methods of bidirectional iterators excluding the following)

  • DerivedT &operator++();
  • DerivedT &operator--(); (and plus the following)
  • bool operator<(const DerivedT &RHS) const;
  • DifferenceTypeT operator-(const DerivedT &R) const;
  • DerivedT &operator+=(DifferenceTypeT N);
  • DerivedT &operator-=(DifferenceTypeT N);

Member Typedef Documentation

◆ difference_type

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::difference_type = DifferenceTypeT

◆ iterator_category

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::iterator_category = IteratorCategoryT

◆ pointer

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::pointer = PointerT

◆ reference

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::reference = ReferenceT

◆ value_type

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
using LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::value_type = T

Member Function Documentation

◆ operator!=()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
bool LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator!= ( const DerivedT & RHS) const
inline

◆ operator+()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator+ ( DifferenceTypeT n) const
inline

◆ operator++() [1/2]

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT & LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator++ ( )
inline

◆ operator++() [2/2]

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator++ ( int )
inline

◆ operator-()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator- ( DifferenceTypeT n) const
inline

◆ operator--() [1/2]

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT & LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator-- ( )
inline

◆ operator--() [2/2]

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
DerivedT LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator-- ( int )
inline

◆ operator->()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
PointerProxy LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator-> ( ) const
inline

◆ operator<=()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
bool LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator<= ( const DerivedT & RHS) const
inline

◆ operator>()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
bool LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator> ( const DerivedT & RHS) const
inline

◆ operator>=()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
bool LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator>= ( const DerivedT & RHS) const
inline

◆ operator[]()

template<typename DerivedT , typename IteratorCategoryT , typename T , typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *, typename ReferenceT = T &>
ReferenceProxy LIEF::iterator_facade_base< DerivedT, IteratorCategoryT, T, DifferenceTypeT, PointerT, ReferenceT >::operator[] ( DifferenceTypeT n) const
inline

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