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 2013-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_FIND_IF_HPP
0014 #define RANGES_V3_ALGORITHM_FIND_IF_HPP
0015 
0016 #include <utility>
0017 
0018 #include <range/v3/range_fwd.hpp>
0019 
0020 #include <range/v3/functional/identity.hpp>
0021 #include <range/v3/functional/invoke.hpp>
0022 #include <range/v3/iterator/concepts.hpp>
0023 #include <range/v3/iterator/traits.hpp>
0024 #include <range/v3/range/access.hpp>
0025 #include <range/v3/range/concepts.hpp>
0026 #include <range/v3/range/dangling.hpp>
0027 #include <range/v3/range/traits.hpp>
0028 #include <range/v3/utility/static_const.hpp>
0029 
0030 #include <range/v3/detail/prologue.hpp>
0031 
0032 namespace ranges
0033 {
0034     /// \addtogroup group-algorithms
0035     /// @{
0036     RANGES_FUNC_BEGIN(find_if)
0037         /// \brief template function \c find
0038         ///
0039         /// range-based version of the \c find std algorithm
0040         ///
0041         /// \pre `Rng` is a model of the `range` concept
0042         /// \pre `I` is a model of the `input_iterator` concept
0043         /// \pre `S` is a model of the `sentinel_for<I>` concept
0044         /// \pre `P` is a model of the `invocable<V>` concept, where `V` is the
0045         ///      value type of I.
0046         /// \pre `F` models `predicate<X>`, where `X` is the result type
0047         ///      of `invocable<P, V>`
0048         template(typename I, typename S, typename F, typename P = identity)(
0049             requires input_iterator<I> AND sentinel_for<S, I> AND
0050             indirect_unary_predicate<F, projected<I, P>>)
0051         constexpr I RANGES_FUNC(find_if)(I first, S last, F pred, P proj = P{})
0052         {
0053             for(; first != last; ++first)
0054                 if(invoke(pred, invoke(proj, *first)))
0055                     break;
0056             return first;
0057         }
0058 
0059         /// \overload
0060         template(typename Rng, typename F, typename P = identity)(
0061             requires input_range<Rng> AND
0062             indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
0063         constexpr borrowed_iterator_t<Rng> RANGES_FUNC(find_if)(Rng && rng, F pred, P proj = P{})
0064         {
0065             return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
0066         }
0067 
0068     RANGES_FUNC_END(find_if)
0069 
0070     namespace cpp20
0071     {
0072         using ranges::find_if;
0073     }
0074     /// @}
0075 } // namespace ranges
0076 
0077 #include <range/v3/detail/epilogue.hpp>
0078 
0079 #endif