Horizon
is_sorted_until.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Eric Niebler 2013-present
5 // Copyright Gonzalo Brito Gadeschi 2014
6 //
7 // Use, modification and distribution is subject to the
8 // Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 //
12 // Project home: https://github.com/ericniebler/range-v3
13 //
14 // Implementation based on the code in libc++
15 // http://http://libcxx.llvm.org/
16 #ifndef RANGES_V3_ALGORITHM_IS_SORTED_UNTIL_HPP
17 #define RANGES_V3_ALGORITHM_IS_SORTED_UNTIL_HPP
18 
19 #include <range/v3/range_fwd.hpp>
20 
29 #include <range/v3/utility/static_const.hpp>
30 
31 #include <range/v3/detail/prologue.hpp>
32 
33 namespace ranges
34 {
37  RANGES_FUNC_BEGIN(is_sorted_until)
50  template(typename I, typename S, typename R = less, typename P = identity)(
51  requires forward_iterator<I> AND sentinel_for<S, I> AND
52  indirect_strict_weak_order<R, projected<I, P>>)
53  constexpr I RANGES_FUNC(is_sorted_until)(I first, S last, R pred = R{}, P proj = P{})
54  {
55  auto i = first;
56  if(first != last)
57  {
58  while(++i != last)
59  {
60  if(invoke(pred, invoke(proj, *i), invoke(proj, *first)))
61  return i;
62  first = i;
63  }
64  }
65  return i;
66  }
67 
69  template(typename Rng, typename R = less, typename P = identity)(
70  requires forward_range<Rng> AND
71  indirect_strict_weak_order<R, projected<iterator_t<Rng>, P>>)
72  constexpr borrowed_iterator_t<Rng> //
73  RANGES_FUNC(is_sorted_until)(Rng && rng, R pred = R{}, P proj = P{})
74  {
75  return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
76  }
77 
78  RANGES_FUNC_END(is_sorted_until)
79 
80  namespace cpp20
81  {
82  using ranges::is_sorted_until;
83  }
85 } // namespace ranges
86 
87 #include <range/v3/detail/epilogue.hpp>
88 
89 #endif
CPP_concept indirect_strict_weak_order
\concept indirect_strict_weak_order
Definition: concepts.hpp:689
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251
bool_<(T::type::value< U::type::value)> less
A Boolean integral constant wrapper around true if T::type::value is less than U::type::value; false,...
Definition: meta.hpp:255