Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

is_partitioned.hpp 2.6KB

5 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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