inplace_merge.qbk 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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:inplace_merge inplace_merge]
  7. [heading Prototype]
  8. ``
  9. template<class BidirectionalRange>
  10. BidirectionalRange&
  11. inplace_merge( BidirectionalRange& rng,
  12. typename range_iterator<BidirectionalRange>::type middle );
  13. template<class BidirectionalRange>
  14. const BidirectionalRange&
  15. inplace_merge( const BidirectionalRange& rng,
  16. typename range_iterator<const BidirectionalRange>::type middle );
  17. template<class BidirectionalRange, class BinaryPredicate>
  18. BidirectionalRange&
  19. inplace_merge( BidirectionalRange& rng,
  20. typename range_iterator<BidirectionalRange>::type middle,
  21. BinaryPredicate pred );
  22. template<class BidirectionalRange, class BinaryPredicate>
  23. const BidirectionalRange&
  24. inplace_merge( const BidirectionalRange& rng,
  25. typename range_iterator<const BidirectionalRange>::type middle,
  26. BinaryPredicate pred );
  27. ``
  28. [heading Description]
  29. `inplace_merge` combines two consecutive sorted ranges `[begin(rng), middle)` and `[middle, end(rng))` into a single sorted range `[begin(rng), end(rng))`. That is, it starts with a range `[begin(rng), end(rng))` that consists of two pieces each of which is in ascending order, and rearranges it so that the entire range is in ascending order. `inplace_merge` is stable, meaning both that the relative order of elements within each input range is preserved.
  30. [heading Definition]
  31. Defined in the header file `boost/range/algorithm/inplace_merge.hpp`
  32. [heading Requirements]
  33. [*For the non-predicate version:]
  34. * `BidirectionalRange` is a model of the __bidirectional_range__ Concept.
  35. * `BidirectionalRange` is mutable.
  36. * `range_value<BidirectionalRange>::type` is a model of `LessThanComparableConcept`
  37. * The ordering on objects of `range_type<BidirectionalRange>::type` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements.
  38. [*For the predicate version:]
  39. * `BidirectionalRange` is a model of the __bidirectional_range__ Concept.
  40. * `BidirectionalRange` is mutable.
  41. * `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`.
  42. * `BidirectionalRange`'s value type is convertible to both `BinaryPredicate`'s argument types.
  43. [heading Precondition:]
  44. [heading For the non-predicate version:]
  45. * `middle` is in the range `rng`.
  46. * `[begin(rng), middle)` is in ascending order. That is for each pair of adjacent elements `[x,y]`, `y < x` is `false`.
  47. * `[middle, end(rng))` is in ascending order. That is for each pair of adjacent elements `[x,y]`, `y < x` is `false`.
  48. [heading For the predicate version:]
  49. * `middle` is in the range `rng`.
  50. * `[begin(rng), middle)` is in ascending order. That is for each pair of adjacent elements `[x,y]`, `pred(y,x) == false`.
  51. * `[middle, end(rng))` is in ascending order. That is for each pair of adjacent elements `[x,y]`, `pred(y,x) == false`.
  52. [heading Complexity]
  53. Worst case: `O(N log(N))`
  54. [endsect]