Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards


Class template counting_iterator

boost::compute::counting_iterator — The counting_iterator class implements a counting iterator.


// In header: <boost/compute/iterator/counting_iterator.hpp>

template<typename T> 
class counting_iterator {
  // types
  typedef unspecified                 super_type;     
  typedef super_type::reference       reference;      
  typedef super_type::difference_type difference_type;

  // construct/copy/destruct
  counting_iterator(const T &);
  counting_iterator(const counting_iterator< T > &);
  counting_iterator< T > & operator=(const counting_iterator< T > &);

  // public member functions
  size_t get_index() const;
  template<typename Expr> unspecified operator[](const Expr &) const;

  // private member functions
  reference dereference() const;
  bool equal(const counting_iterator< T > &) const;
  void increment();
  void decrement();
  void advance(difference_type);
  difference_type distance_to(const counting_iterator< T > &) const;


A counting iterator returns an internal value (initialized with init) which is incremented each time the iterator is incremented.

For example, this could be used to implement the iota() algorithm in terms of the copy() algorithm by copying from a range of counting iterators:

See Also:


counting_iterator public construct/copy/destruct

  1. counting_iterator(const T & init);
  2. counting_iterator(const counting_iterator< T > & other);
  3. counting_iterator< T > & operator=(const counting_iterator< T > & other);
  4. ~counting_iterator();

counting_iterator public member functions

  1. size_t get_index() const;
  2. template<typename Expr> unspecified operator[](const Expr & expr) const;

counting_iterator private member functions

  1. reference dereference() const;
  2. bool equal(const counting_iterator< T > & other) const;
  3. void increment();
  4. void decrement();
  5. void advance(difference_type n);
  6. difference_type distance_to(const counting_iterator< T > & other) const;