PrevUpHomeNext

Class template counting_iterator

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

Synopsis

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

template<typename T> 
class counting_iterator {
public:
  // 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 > &);
  ~counting_iterator();

  // 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;
};

Description

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:

using boost::compute::make_counting_iterator;

boost::compute::vector<int> result(5, context);

boost::compute::copy(
    make_counting_iterator(1), make_counting_iterator(6), result.begin(), queue
);

// result == { 1, 2, 3, 4, 5 }

See Also:

make_counting_iterator()

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;

PrevUpHomeNext