Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:54:37

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