| Home | Libraries | People | FAQ | More

## Function template copy

boost::compute::copy

## Synopsis

    // In header: <boost/compute/algorithm/copy.hpp>

    template<typename InputIterator, typename OutputIterator>
      OutputIterator
      copy(InputIterator first, InputIterator last, OutputIterator result,
           command_queue & queue = system::default_queue(),
           const wait_list & events = wait_list());

## Description

Copies the values in the range [`first`, `last`) to the range beginning at `result`.

The generic copy() function can be used for a variety of data transfer tasks and provides a standard interface to the following OpenCL functions:

- `clEnqueueReadBuffer()`

- `clEnqueueWriteBuffer()`

- `clEnqueueCopyBuffer()`

Unlike the aforementioned OpenCL functions, copy() will also work with non-contiguous data-structures (e.g. `std::list<T>`) as well as with "fancy" iterators (e.g. transform_iterator).

For example, to copy an array of `int` values on the host to a vector on the device:

    // array on the host
    int data[] = { 1, 2, 3, 4 };

    // vector on the device
    boost::compute::vector<int> vec(4, context);

    // copy values to the device vector
    boost::compute::copy(data, data + 4, vec.begin(), queue);

The copy algorithm can also be used with standard containers such as `std::vector<T>`:

    std::vector<int> host_vector = ...
    boost::compute::vector<int> device_vector = ...

    // copy from the host to the device
    boost::compute::copy(
        host_vector.begin(), host_vector.end(), device_vector.begin(), queue
    );

    // copy from the device to the host
    boost::compute::copy(
        device_vector.begin(), device_vector.end(), host_vector.begin(), queue
    );

Space complexity: \Omega(1)

See Also: copy_n(), copy_if(), copy_async()

Parameters: |
`first` | first element in the range to copy
`last` | last element in the range to copy
`result` | first element in the result range
`queue` | command queue to perform the operation
Returns: | `OutputIterator` to the end of the result range