merge.qbk 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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:merge merge]
  7. [heading Prototype]
  8. ``
  9. template<
  10. class SinglePassRange1,
  11. class SinglePassRange2,
  12. class OutputIterator
  13. >
  14. OutputIterator merge(const SinglePassRange1& rng1,
  15. const SinglePassRange2& rng2,
  16. OutputIterator out);
  17. template<
  18. class SinglePassRange1,
  19. class SinglePassRange2,
  20. class OutputIterator,
  21. class BinaryPredicate
  22. >
  23. OutputIterator merge(const SinglePassRange1& rng1,
  24. const SinglePassRange2& rng2,
  25. OutputIterator out,
  26. BinaryPredicate pred);
  27. ``
  28. [heading Description]
  29. `merge` combines two sorted ranges `rng1` and `rng2` into a single sorted range by copying elements. `merge` is stable. The return value is `out + distance(rng1) + distance(rng2)`.
  30. The two versions of `merge` differ by how they compare the elements.
  31. The non-predicate version uses the `operator<()` for the range value type. The predicate version uses the predicate instead of `operator<()`.
  32. [heading Definition]
  33. Defined in the header file `boost/range/algorithm/merge.hpp`
  34. [heading Requirements]
  35. [*For the non-predicate version:]
  36. * `SinglePassRange1` is a model of the __single_pass_range__ Concept.
  37. * `SinglePassRange2` is a model of the __single_pass_range__ Concept.
  38. * `range_value<SinglePassRange1>::type` is the same as `range_value<SinglePassRange2>::type`.
  39. * `range_value<SinglePassRange1>::type` is a model of the `LessThanComparableConcept`.
  40. * The ordering on objects of `range_value<SinglePassRange1>::type` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements.
  41. * `range_value<SinglePassRange1>::type` is convertible to a type in `OutputIterator`'s set of value types.
  42. [*For the predicate version:]
  43. * `SinglePassRange1` is a model of the __single_pass_range__ Concept.
  44. * `SinglePassRange2` is a model of the __single_pass_range__ Concept.
  45. * `range_value<SinglePassRange1>::type` is the same as `range_value<SinglePassRange2>::type`.
  46. * `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`.
  47. * `SinglePassRange1`'s value type is convertible to both `BinaryPredicate`'s argument types.
  48. * `range_value<SinglePassRange1>::type` is convertible to a type in `OutputIterator`'s set of value types.
  49. [heading Precondition:]
  50. [heading For the non-predicate version:]
  51. * The elements of `rng1` are in ascending order. That is, for each adjacent element pair `[x,y]` of `rng1`, `y < x == false`.
  52. * The elements of `rng2` are in ascending order. That is, for each adjacent element pair `[x,y]` of `rng2`, `y < x == false`.
  53. * The ranges `rng1` and `[out, out + distance(rng1) + distance(rng2))` do not overlap.
  54. * The ranges `rng2` and `[out, out + distance(rng1) + distance(rng2))` do not overlap.
  55. * `[out, out + distance(rng1) + distance(rng2))` is a valid range.
  56. [heading For the predicate version:]
  57. * The elements of `rng1` are in ascending order. That is, for each adjacent element pair `[x,y]`, of `rng1`, `pred(y, x) == false`.
  58. * The elements of `rng2` are in ascending order. That is, for each adjacent element pair `[x,y]`, of `rng2`, `pred(y, x) == false`.
  59. * The ranges `rng1` and `[out, out + distance(rng1) + distance(rng2))` do not overlap.
  60. * The ranges `rng2` and `[out, out + distance(rng1) + distance(rng2))` do not overlap.
  61. * `[out, out + distance(rng1) + distance(rng2))` is a valid range.
  62. [heading Complexity]
  63. Linear. There are no comparisons if both `rng1` and `rng2` are empty, otherwise at most `distance(rng1) + distance(rng2) - 1` comparisons.
  64. [endsect]