| 1 |
/// \file |
| 2 |
// 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 |
|
| 21 |
#include <range/v3/functional/identity.hpp> |
| 22 |
#include <range/v3/functional/invoke.hpp> |
| 23 |
#include <range/v3/iterator/concepts.hpp> |
| 24 |
#include <range/v3/iterator/traits.hpp> |
| 25 |
#include <range/v3/range/access.hpp> |
| 26 |
#include <range/v3/range/concepts.hpp> |
| 27 |
#include <range/v3/range/traits.hpp> |
| 28 |
#include <range/v3/utility/static_const.hpp> |
| 29 |
|
| 30 |
#include <range/v3/detail/prologue.hpp> |
| 31 |
|
| 32 |
namespace ranges |
| 33 |
{ |
| 34 |
/// \addtogroup group-algorithms |
| 35 |
/// @{ |
| 36 |
RANGES_FUNC_BEGIN(any_of) |
| 37 |
|
| 38 |
/// \brief function template \c any_of |
| 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 |
|
| 50 |
/// \overload |
| 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 |
} |
| 65 |
/// @} |
| 66 |
} // namespace ranges |
| 67 |
|
| 68 |
#include <range/v3/detail/epilogue.hpp> |
| 69 |
|
| 70 |
#endif |