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.

79 lines
2.6KB

  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2014-present
  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. //===-------------------------- algorithm ---------------------------------===//
  14. //
  15. // The LLVM Compiler Infrastructure
  16. //
  17. // This file is dual licensed under the MIT and the University of Illinois Open
  18. // Source Licenses. See LICENSE.TXT for details.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. #ifndef RANGES_V3_ALGORITHM_IS_PARTITIONED_HPP
  22. #define RANGES_V3_ALGORITHM_IS_PARTITIONED_HPP
  23. #include <meta/meta.hpp>
  24. #include <range/v3/range_fwd.hpp>
  25. #include <range/v3/functional/identity.hpp>
  26. #include <range/v3/functional/invoke.hpp>
  27. #include <range/v3/iterator/concepts.hpp>
  28. #include <range/v3/iterator/traits.hpp>
  29. #include <range/v3/range/access.hpp>
  30. #include <range/v3/range/concepts.hpp>
  31. #include <range/v3/range/traits.hpp>
  32. #include <range/v3/utility/static_const.hpp>
  33. namespace ranges
  34. {
  35. /// \addtogroup group-algorithms
  36. /// @{
  37. RANGES_BEGIN_NIEBLOID(is_partitioned)
  38. /// \brief function template \c is_partitioned
  39. template<typename I, typename S, typename C, typename P = identity>
  40. auto RANGES_FUN_NIEBLOID(is_partitioned)(I first, S last, C pred, P proj = P{}) //
  41. ->CPP_ret(bool)( //
  42. requires input_iterator<I> && sentinel_for<S, I> &&
  43. indirect_unary_predicate<C, projected<I, P>>)
  44. {
  45. for(; first != last; ++first)
  46. if(!invoke(pred, invoke(proj, *first)))
  47. break;
  48. for(; first != last; ++first)
  49. if(invoke(pred, invoke(proj, *first)))
  50. return false;
  51. return true;
  52. }
  53. /// \overload
  54. template<typename Rng, typename C, typename P = identity>
  55. auto RANGES_FUN_NIEBLOID(is_partitioned)(Rng && rng, C pred, P proj = P{}) //
  56. ->CPP_ret(bool)( //
  57. requires input_range<Rng> &&
  58. indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
  59. {
  60. return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
  61. }
  62. RANGES_END_NIEBLOID(is_partitioned)
  63. namespace cpp20
  64. {
  65. using ranges::is_partitioned;
  66. }
  67. /// @}
  68. } // namespace ranges
  69. #endif // include guard