Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:53

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2014-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_ALGORITHM_COPY_IF_HPP
0014 #define RANGES_V3_ALGORITHM_COPY_IF_HPP
0015 
0016 #include <functional>
0017 #include <utility>
0018 
0019 #include <range/v3/range_fwd.hpp>
0020 
0021 #include <range/v3/algorithm/result_types.hpp>
0022 #include <range/v3/functional/identity.hpp>
0023 #include <range/v3/functional/invoke.hpp>
0024 #include <range/v3/iterator/concepts.hpp>
0025 #include <range/v3/iterator/traits.hpp>
0026 #include <range/v3/range/access.hpp>
0027 #include <range/v3/range/concepts.hpp>
0028 #include <range/v3/range/dangling.hpp>
0029 #include <range/v3/range/traits.hpp>
0030 #include <range/v3/utility/static_const.hpp>
0031 
0032 #include <range/v3/detail/prologue.hpp>
0033 
0034 namespace ranges
0035 {
0036     /// \addtogroup group-algorithms
0037     /// @{
0038     template<typename I, typename O>
0039     using copy_if_result = detail::in_out_result<I, O>;
0040 
0041     RANGES_FUNC_BEGIN(copy_if)
0042 
0043         /// \brief function template \c copy_if
0044         template(typename I, typename S, typename O, typename F, typename P = identity)(
0045             requires input_iterator<I> AND sentinel_for<S, I> AND
0046                 weakly_incrementable<O> AND
0047                 indirect_unary_predicate<F, projected<I, P>> AND
0048                 indirectly_copyable<I, O>)
0049         constexpr copy_if_result<I, O> //
0050         RANGES_FUNC(copy_if)(I first, S last, O out, F pred, P proj = P{}) //
0051         {
0052             for(; first != last; ++first)
0053             {
0054                 auto && x = *first;
0055                 if(invoke(pred, invoke(proj, x)))
0056                 {
0057                     *out = (decltype(x) &&)x;
0058                     ++out;
0059                 }
0060             }
0061             return {first, out};
0062         }
0063 
0064         /// \overload
0065         template(typename Rng, typename O, typename F, typename P = identity)(
0066             requires input_range<Rng> AND weakly_incrementable<O> AND
0067             indirect_unary_predicate<F, projected<iterator_t<Rng>, P>> AND
0068             indirectly_copyable<iterator_t<Rng>, O>)
0069         constexpr copy_if_result<borrowed_iterator_t<Rng>, O> //
0070         RANGES_FUNC(copy_if)(Rng && rng, O out, F pred, P proj = P{})
0071         {
0072             return (*this)(
0073                 begin(rng), end(rng), std::move(out), std::move(pred), std::move(proj));
0074         }
0075 
0076     RANGES_FUNC_END(copy_if)
0077 
0078     namespace cpp20
0079     {
0080         using ranges::copy_if;
0081         using ranges::copy_if_result;
0082     } // namespace cpp20
0083     /// @}
0084 } // namespace ranges
0085 
0086 #include <range/v3/detail/epilogue.hpp>
0087 
0088 #endif