| 1 |
/// \file |
| 2 |
// Range v3 library |
| 3 |
// |
| 4 |
// Copyright Andrew Sutton 2014 |
| 5 |
// |
| 6 |
// Use, modification and distribution is subject to the |
| 7 |
// Boost Software License, Version 1.0. (See accompanying |
| 8 |
// file LICENSE_1_0.txt or copy at |
| 9 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 10 |
// |
| 11 |
// Project home: https://github.com/ericniebler/range-v3 |
| 12 |
// |
| 13 |
#ifndef RANGES_V3_ALGORITHM_ALL_OF_HPP |
| 14 |
#define RANGES_V3_ALGORITHM_ALL_OF_HPP |
| 15 |
|
| 16 |
#include <utility> |
| 17 |
|
| 18 |
#include <range/v3/range_fwd.hpp> |
| 19 |
|
| 20 |
#include <range/v3/functional/identity.hpp> |
| 21 |
#include <range/v3/functional/invoke.hpp> |
| 22 |
#include <range/v3/iterator/concepts.hpp> |
| 23 |
#include <range/v3/iterator/traits.hpp> |
| 24 |
#include <range/v3/range/access.hpp> |
| 25 |
#include <range/v3/range/concepts.hpp> |
| 26 |
#include <range/v3/range/traits.hpp> |
| 27 |
#include <range/v3/utility/static_const.hpp> |
| 28 |
|
| 29 |
#include <range/v3/detail/prologue.hpp> |
| 30 |
|
| 31 |
namespace ranges |
| 32 |
{ |
| 33 |
/// \addtogroup group-algorithms |
| 34 |
/// @{ |
| 35 |
RANGES_FUNC_BEGIN(all_of) |
| 36 |
|
| 37 |
/// \brief function template \c all_of |
| 38 |
template(typename I, typename S, typename F, typename P = identity)( |
| 39 |
requires input_iterator<I> AND sentinel_for<S, I> AND |
| 40 |
indirect_unary_predicate<F, projected<I, P>>) |
| 41 |
constexpr bool RANGES_FUNC(all_of)(I first, S last, F pred, P proj = P{}) // |
| 42 |
{ |
| 43 |
for(; first != last; ++first) |
| 44 |
if(!invoke(pred, invoke(proj, *first))) |
| 45 |
break; |
| 46 |
return first == last; |
| 47 |
} |
| 48 |
|
| 49 |
/// \overload |
| 50 |
template(typename Rng, typename F, typename P = identity)( |
| 51 |
requires input_range<Rng> AND |
| 52 |
indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>) |
| 53 |
constexpr bool RANGES_FUNC(all_of)(Rng && rng, F pred, P proj = P{}) // |
| 54 |
{ |
| 55 |
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj)); |
| 56 |
} |
| 57 |
|
| 58 |
RANGES_FUNC_END(all_of) |
| 59 |
|
| 60 |
namespace cpp20 |
| 61 |
{ |
| 62 |
using ranges::all_of; |
| 63 |
} |
| 64 |
/// @} |
| 65 |
} // namespace ranges |
| 66 |
|
| 67 |
#include <range/v3/detail/epilogue.hpp> |
| 68 |
|
| 69 |
#endif |