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 24 #include <meta/meta.hpp> 25 26 #include <range/v3/range_fwd.hpp> 27 28 #include <range/v3/functional/identity.hpp> 29 #include <range/v3/functional/invoke.hpp> 30 #include <range/v3/iterator/concepts.hpp> 31 #include <range/v3/iterator/traits.hpp> 32 #include <range/v3/range/access.hpp> 33 #include <range/v3/range/concepts.hpp> 34 #include <range/v3/range/traits.hpp> 35 #include <range/v3/utility/static_const.hpp> 36 37 #include <range/v3/detail/prologue.hpp> 38 39 namespace ranges 40 { 41 /// \addtogroup group-algorithms 42 /// @{ 43 RANGES_FUNC_BEGIN(is_partitioned) 44 45 /// \brief function template \c is_partitioned 46 template(typename I, typename S, typename C, typename P = identity)( 47 /// \pre 48 requires input_iterator<I> AND sentinel_for<S, I> AND 49 indirect_unary_predicate<C, projected<I, P>>) 50 bool RANGES_FUNC(is_partitioned)(I first, S last, C pred, P proj = P{}) // 51 { 52 for(; first != last; ++first) 53 if(!invoke(pred, invoke(proj, *first))) 54 break; 55 for(; first != last; ++first) 56 if(invoke(pred, invoke(proj, *first))) 57 return false; 58 return true; 59 } 60 61 /// \overload 62 template(typename Rng, typename C, typename P = identity)( 63 /// \pre 64 requires input_range<Rng> AND 65 indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>) 66 bool RANGES_FUNC(is_partitioned)(Rng && rng, C pred, P proj = P{}) // 67 { 68 return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj)); 69 } 70 71 RANGES_FUNC_END(is_partitioned) 72 73 namespace cpp20 74 { 75 using ranges::is_partitioned; 76 } 77 /// @} 78 } // namespace ranges 79 80 #include <range/v3/detail/epilogue.hpp> 81 82 #endif 83