sort.qbk 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. [/
  2. Copyright 2010 Neil Groves
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. /]
  6. [section:sort sort]
  7. [heading Prototype]
  8. ``
  9. template<class RandomAccessRange>
  10. RandomAccessRange& sort(RandomAccessRange& rng);
  11. template<class RandomAccessRange>
  12. const RandomAccessRange& sort(const RandomAccessRange& rng);
  13. template<class RandomAccessRange, class BinaryPredicate>
  14. RandomAccessRange& sort(RandomAccessRange& rng, BinaryPredicate pred);
  15. template<class RandomAccessRange, class BinaryPredicate>
  16. const RandomAccessRange& sort(const RandomAccessRange& rng, BinaryPredicate pred);
  17. ``
  18. [heading Description]
  19. `sort` sorts the elements in `rng` into ascending order. `sort` is not guaranteed to be stable. Returns the sorted range.
  20. For versions of the `sort` function without a predicate, ascending order is defined by `operator<()` such that for all adjacent elements `[x,y]`, `y < x == false`.
  21. For versions of the `sort` function with a predicate, ascending order is defined by `pred` such that for all adjacent elements `[x,y]`, `pred(y, x) == false`.
  22. [heading Definition]
  23. Defined in the header file `boost/range/algorithm/sort.hpp`
  24. [heading Requirements]
  25. [*For versions of sort without a predicate:]
  26. * `RandomAccessRange` is a model of the __random_access_range__ Concept.
  27. * `RandomAccessRange` is mutable.
  28. * `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`.
  29. * The ordering relation on `RandomAccessRange`'s value type is a [*strict weak ordering], as defined in the `LessThanComparableConcept` requirements.
  30. [*For versions of sort with a predicate]
  31. * `RandomAccessRange` is a model of the __random_access_range__ Concept.
  32. * `RandomAccessRange` is mutable.
  33. * `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`.
  34. * `RandomAccessRange`'s value type is convertible to both of `BinaryPredicate`'s argument types.
  35. [heading Complexity]
  36. `O(N log(N))` comparisons (both average and worst-case), where `N` is `distance(rng)`.
  37. [endsect]