Horizon
any_of.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Andrew Sutton 2014
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 #ifndef RANGES_V3_ALGORITHM_ANY_OF_HPP
15 #define RANGES_V3_ALGORITHM_ANY_OF_HPP
16 
17 #include <utility>
18 
19 #include <range/v3/range_fwd.hpp>
20 
28 #include <range/v3/utility/static_const.hpp>
29 
30 #include <range/v3/detail/prologue.hpp>
31 
32 namespace ranges
33 {
36  RANGES_FUNC_BEGIN(any_of)
37 
38 
39  template(typename I, typename S, typename F, typename P = identity)(
40  requires input_iterator<I> AND sentinel_for<S, I> AND
41  indirect_unary_predicate<F, projected<I, P>>)
42  constexpr bool RANGES_FUNC(any_of)(I first, S last, F pred, P proj = P{}) //
43  {
44  for(; first != last; ++first)
45  if(invoke(pred, invoke(proj, *first)))
46  return true;
47  return false;
48  }
49 
51  template(typename Rng, typename F, typename P = identity)(
52  requires input_range<Rng> AND
53  indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
54  constexpr bool RANGES_FUNC(any_of)(Rng && rng, F pred, P proj = P{}) //
55  {
56  return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
57  }
58 
59  RANGES_FUNC_END(any_of)
60 
61  namespace cpp20
62  {
63  using ranges::any_of;
64  }
66 } // namespace ranges
67 
68 #include <range/v3/detail/epilogue.hpp>
69 
70 #endif
CPP_concept indirect_unary_predicate
\concept indirect_unary_predicate
Definition: concepts.hpp:632
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