A library for working with phylogenetic and population genetic data.
v0.27.0
DereferenceIterator< BaseIterator > Class Template Reference

#include <genesis/utils/containers/deref_iterator.hpp>

Inherits BaseIterator.

Detailed Description

template<class BaseIterator>
class genesis::utils::DereferenceIterator< BaseIterator >

Iterator class that exposes elements in a container of pointers.

This class can be used as an iterator into a container of pointers, in order to avoid double dereferencing of the elements:

std::vector<std::unique_ptr<T>> foo;
for( auto& it : foo ){
    auto const baz = (*it)->bar;
}

This is cumbersome. By using this class, the double dereferencing is not needed. See Tree class for an exemplary usage of this technique.

Inspired by https://jonasdevlieghere.com/containers-of-unique-pointers/

Definition at line 60 of file deref_iterator.hpp.

Public Member Functions

 DereferenceIterator (BaseIterator const &other)
 
reference operator* () const
 
pointer operator-> () const
 
reference operator[] (difference_type n) const
 

Public Types

using difference_type = typename BaseIterator::difference_type
 
using pointer = value_type *
 
using reference = value_type &
 
using value_type = typename BaseIterator::value_type::element_type
 

Constructor & Destructor Documentation

◆ DereferenceIterator()

DereferenceIterator ( BaseIterator const &  other)
inline

Definition at line 70 of file deref_iterator.hpp.

Member Function Documentation

◆ operator*()

reference operator* ( ) const
inline

Definition at line 74 of file deref_iterator.hpp.

◆ operator->()

pointer operator-> ( ) const
inline

Definition at line 79 of file deref_iterator.hpp.

◆ operator[]()

reference operator[] ( difference_type  n) const
inline

Definition at line 84 of file deref_iterator.hpp.

Member Typedef Documentation

◆ difference_type

using difference_type = typename BaseIterator::difference_type

Definition at line 65 of file deref_iterator.hpp.

◆ pointer

using pointer = value_type *

Definition at line 67 of file deref_iterator.hpp.

◆ reference

using reference = value_type &

Definition at line 68 of file deref_iterator.hpp.

◆ value_type

using value_type = typename BaseIterator::value_type::element_type

Definition at line 64 of file deref_iterator.hpp.


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