| Home | Libraries | People | FAQ | More

## Spreadsort

### Header `<boost/sort/spreadsort/spreadsort.hpp>`

``spreadsort`` checks whether the data-type provided is an integer, castable float, string, or wstring.

- If data-type is an integer, ``integer_sort`` is used.
- If data-type is a float, ``float_sort`` is used.
- If data-type is a string or wstring, ``string_sort`` is used.
- Sorting other data-types requires picking between ``integer_sort``, ``float_sort`` and ``string_sort`` directly, as ``spreadsort`` won't accept types that don't have the appropriate type traits.

Overloading variants are provided that permit use of user-defined right-shift functors and comparison functors.

Each function is optimized for its set of arguments; default functors are not provided to avoid the risk of any reduction of performance.

See overloading section.

###### Rationale:

``spreadsort`` function provides a wrapper that calls the fastest sorting algorithm available for a data-type, enabling faster generic programming.

#### Spreadsort Examples

See example folder for all examples.

See sample.cpp for a simple working example.

For an example of 64-bit integer sorting, see int64.cpp.

This example sets the element type of a vector to 64-bit integer

    #define DATA_TYPE boost::int64_t

and calls the sort

    boost::sort::spreadsort::spreadsort(array.begin(), array.end());

For a simple example sorting `float`s,

    vector<float> vec;
    vec.push_back(1.0);
    vec.push_back(2.3);
    vec.push_back(1.3);
    ...
    spreadsort(vec.begin(), vec.end());
    //The sorted vector contains "1.0 1.3 2.3 ..."

See also floatsample.cpp which checks for abnormal values.