is_partitioned_until.qbk 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. [/ File is_partitioned_until.qbk]
  2. [section:is_partitioned_until is_partitioned_until ]
  3. [/license
  4. Copyright (c) 2017 Alexander Zaitsev
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ]
  8. The header file 'is_partitioned_until.hpp' contains two variants of a single algorithm, `is_partitioned_until`. The algorithm tests to see if a sequence is partitioned according to a predicate; in other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence.
  9. The routine `is_partitioned_until` takes a sequence and a predicate. It returns the last iterator 'it' in the sequence [begin, end) for which the is_partitioned(begin, it) is true.
  10. `is_partitioned_until` come in two forms; the first one takes two iterators to define the range. The second form takes a single range parameter, and uses Boost.Range to traverse it.
  11. [heading interface]
  12. The function `is_partitioned_until` returns the last iterator 'it' in the sequence [begin, end) for which the is_partitioned(begin, it) is true. There are two versions; one takes two iterators, and the other takes a range.
  13. ``
  14. template<typename InputIterator, typename Predicate>
  15. InputIterator is_partitioned_until ( InputIterator first, InputIterator last, Predicate p );
  16. template<typename Range, typename Predicate>
  17. typename boost::range_iterator<const Range>::type is_partitioned_until ( const Range &r, Predicate p );
  18. ``
  19. [heading Examples]
  20. Given the container `c` containing `{ 0, 1, 2, 3, 14, 15 }`, then
  21. ``
  22. bool isOdd ( int i ) { return i % 2 == 1; }
  23. bool lessThan10 ( int i ) { return i < 10; }
  24. is_partitioned_until ( c, isOdd ) --> iterator to '1'
  25. is_partitioned_until ( c, lessThan10 ) --> end
  26. is_partitioned_until ( c.begin (), c.end (), lessThan10 ) --> end
  27. is_partitioned_until ( c.begin (), c.begin () + 3, lessThan10 ) --> end
  28. is_partitioned_until ( c.end (), c.end (), isOdd ) --> end // empty range
  29. ``
  30. [heading Iterator Requirements]
  31. `is_partitioned_until` works on all iterators except output iterators.
  32. [heading Complexity]
  33. Both of the variants of `is_partitioned_until` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If the sequence is found to be not partitioned at any point, the routine will terminate immediately, without examining the rest of the elements.
  34. [heading Exception Safety]
  35. Both of the variants of `is_partitioned_until` take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee.
  36. [heading Notes]
  37. * `is_partitioned_until` returns iterator to the end for empty and single-element ranges, no matter what predicate is passed to test against.
  38. [endsect]
  39. [/ File is_partitioned_until.qbk
  40. Copyright 2017 Alexander Zaitsev
  41. Distributed under the Boost Software License, Version 1.0.
  42. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
  43. ]