| Home | Libraries | People | FAQ | More

## Function template sort

boost::compute::sort

## Synopsis

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

    template<typename Iterator, typename Compare>
      void sort(Iterator first, Iterator last, Compare compare,
                command_queue & queue = system::default_queue());

## Description

Sorts the values in the range [`first`, `last`) according to `compare`.

For example, to sort a vector on the device:

    // create vector on the device with data
    float data[] = { 2.f, 4.f, 1.f, 3.f };
    boost::compute::vector<float> vec(data, data + 4, queue);

    // sort the vector on the device
    boost::compute::sort(vec.begin(), vec.end(), queue);

The sort() algorithm can also be directly used with host iterators. This example will automatically transfer the data to the device, sort it, and then transfer the data back to the host:

    std::vector<int> data = { 9, 3, 2, 5, 1, 4, 6, 7 };

    boost::compute::sort(data.begin(), data.end(), queue);

Space complexity: \Omega(n)

See Also:

is_sorted()

Parameters: |
`compare` | comparison function (by default `less`)
`first` | first element in the range to sort
`last` | last element in the range to sort
`queue` | command queue to perform the operation