trsl logo
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
trsl::reorder_iterator< ElementIterator > Class Template Reference

Provides an iterator over a permutation of a range. More...

#include <reorder_iterator.hpp>

Public Types

typedef base_t::index_t index_t
 
typedef base_t::index_container index_container
 
typedef base_t::index_container_ptr index_container_ptr
 
typedef base_t::index_iterator index_iterator
 
typedef base_t::element_iterator element_iterator
 

Public Member Functions

 reorder_iterator (ElementIterator first, const index_container_ptr &index_collection)
 Constructs an iterator that will walk through the elements of the range that begins at first, follwing the order defined by index_collection.
 
template<class OtherElementIterator >
 reorder_iterator (reorder_iterator< OtherElementIterator > const &r, typename boost::enable_if_convertible< OtherElementIterator, ElementIterator >::type *=0)
 Allows conversion from a reorder_iterator to a const reorder_iterator, won't allow conversion from a const reorder_iterator to a reorder_iterator. More...
 
reorder_iterator< ElementIterator > begin () const
 Returns a reorder_iterator pointing to the begining of the permutation.
 
reorder_iterator< ElementIterator > end () const
 Returns a reorder_iterator pointing to the end of the permutation.
 
index_t index () const
 Returns the index of the element that the iterator is currently pointing to.
 

Protected Attributes

index_container_ptr m_index_collection
 

Friends

class boost::iterator_core_access
 

Detailed Description

template<class ElementIterator>
class trsl::reorder_iterator< ElementIterator >

Provides an iterator over a permutation of a range.

This class is a fork of boost::permutation_iterator. With boost::permutation_iterator, the user provides a population, and a range of index that defines a permutation over the population. It allows for much flexibility, but leaves the user responsible for storing an array of index. This class allows to store the array internally, in the same way as boost::shared_container_iterator.

The index array is stored within the iterator, by means of a boost::shared_ptr; thus, all copies of a reorder iterator share the same index array. One drawback is that reorder_iterator copy is somewhat slower than ElementIterator copy. Incrementation is still plainly efficient, nevertheless.

When iterating over a permutation of a population range using an index range, the iteration is actually performed over the index range; the population range is only used when dereferencing. Thus, every trsl::reorder_iterator knows where it begins and where it ends, hence provided begin() and end() methods.

TRSL provides several functions that generate reoder iterators for common reorderings. See random_permutation_iterator() and sort_iterator().

ElementIterator should model Random Access Iterator. See the doc on boost::permutation_iterator for further details.

Examples
trsl_example2.cpp.

Definition at line 31 of file reorder_iterator.hpp.

Constructor & Destructor Documentation

◆ reorder_iterator()

template<class ElementIterator >
template<class OtherElementIterator >
trsl::reorder_iterator< ElementIterator >::reorder_iterator ( reorder_iterator< OtherElementIterator > const &  r,
typename boost::enable_if_convertible< OtherElementIterator, ElementIterator >::type *  = 0 
)
inline

Allows conversion from a reorder_iterator to a const reorder_iterator, won't allow conversion from a const reorder_iterator to a reorder_iterator.

By “const reorder_iterator”, we mean that the ElementIterator is const, e.g. std::vector<Particle>::const_iterator.

Definition at line 142 of file reorder_iterator.hpp.


The documentation for this class was generated from the following file:
© Copyright 2007-2011 Renaud Detry.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt.)
Revised Wed Jan 8 2020 14:43:32.