You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1KB

  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. #include <utility>
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/functional/identity.hpp>
  18. #include <range/v3/functional/invoke.hpp>
  19. #include <range/v3/iterator/concepts.hpp>
  20. #include <range/v3/iterator/traits.hpp>
  21. #include <range/v3/range/access.hpp>
  22. #include <range/v3/range/concepts.hpp>
  23. #include <range/v3/range/traits.hpp>
  24. #include <range/v3/utility/static_const.hpp>
  25. namespace ranges
  26. {
  27. /// \addtogroup group-algorithms
  28. /// @{
  29. RANGES_BEGIN_NIEBLOID(all_of)
  30. /// \brief function template \c all_of
  31. template<typename I, typename S, typename F, typename P = identity>
  32. auto RANGES_FUN_NIEBLOID(all_of)(I first, S last, F pred, P proj = P{}) //
  33. ->CPP_ret(bool)( //
  34. requires input_iterator<I> && sentinel_for<S, I> &&
  35. indirect_unary_predicate<F, projected<I, P>>)
  36. {
  37. for(; first != last; ++first)
  38. if(!invoke(pred, invoke(proj, *first)))
  39. break;
  40. return first == last;
  41. }
  42. /// \overload
  43. template<typename Rng, typename F, typename P = identity>
  44. auto RANGES_FUN_NIEBLOID(all_of)(Rng && rng, F pred, P proj = P{}) //
  45. ->CPP_ret(bool)( //
  46. requires input_range<Rng> &&
  47. indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
  48. {
  49. return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
  50. }
  51. RANGES_END_NIEBLOID(all_of)
  52. namespace cpp20
  53. {
  54. using ranges::all_of;
  55. }
  56. /// @}
  57. } // namespace ranges
  58. #endif // include guard