Class template buffer_iterator

| Home | Libraries | People | FAQ | More

## Class template buffer_iterator

boost::compute::buffer_iterator — An iterator for values in a buffer.

## Synopsis

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

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

      // construct/copy/destruct
      buffer_iterator();
      buffer_iterator(const buffer &, size_t);
      buffer_iterator(const buffer_iterator< T > &);
      buffer_iterator< T > & operator=(const buffer_iterator< T > &);
      ~buffer_iterator();

      // public member functions
      const buffer & get_buffer() const;
      size_t get_index() const;
      T read(command_queue &) const;
      void write(const T &, command_queue &);
    };

## Description

The buffer_iterator class iterates over values in a memory buffer on a compute device. It is the most commonly used iterator in Boost.Compute and is used by the vector<T> and array<T, N> container classes.

Buffer iterators store a reference to a memory buffer along with an index into that memory buffer.

The buffer_iterator class allows for arbitrary OpenCL memory objects (including those created outside of Boost.Compute) to be used with the Boost.Compute algorithms (such as transform() and sort()). For example, to reverse the contents of an OpenCL memory buffer containing a set of integers:

    // create a buffer object wrapping the cl_mem object
    boost::compute::buffer buf(external_mem_obj);

    // reverse the values in the buffer
    boost::compute::reverse(
        boost::compute::make_buffer_iterator<int>(buf, 0),
        boost::compute::make_buffer_iterator<int>(buf, 3),
        queue
    );

See Also:

buffer, make_buffer_iterator()

### `buffer_iterator` public construct/copy/destruct

1.     buffer_iterator();

2.     buffer_iterator(const buffer & buffer, size_t index);

3.     buffer_iterator(const buffer_iterator< T > & other);

4.     buffer_iterator< T > & operator=(const buffer_iterator< T > & other);

5.     ~buffer_iterator();

### `buffer_iterator` public member functions

1.     const buffer & get_buffer() const;

2.     size_t get_index() const;

3.     T read(command_queue & queue) const;

4.     void write(const T & value, command_queue & queue);