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 Johel Guerrero 2019
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_ENDS_WITH_HPP
0014 #define RANGES_V3_ALGORITHM_ENDS_WITH_HPP
0015 
0016 #include <utility>
0017 
0018 #include <concepts/concepts.hpp>
0019 
0020 #include <range/v3/algorithm/equal.hpp>
0021 #include <range/v3/detail/config.hpp>
0022 #include <range/v3/functional/comparisons.hpp>
0023 #include <range/v3/functional/identity.hpp>
0024 #include <range/v3/iterator/concepts.hpp>
0025 #include <range/v3/iterator/operations.hpp>
0026 #include <range/v3/range/access.hpp>
0027 #include <range/v3/range/concepts.hpp>
0028 
0029 #include <range/v3/detail/prologue.hpp>
0030 
0031 namespace ranges
0032 {
0033     /// \addtogroup group-algorithms
0034     /// @{
0035     RANGES_FUNC_BEGIN(ends_with)
0036 
0037         /// \brief function template \c ends_with
0038         template(typename I0,
0039                  typename S0,
0040                  typename I1,
0041                  typename S1,
0042                  typename C = equal_to,
0043                  typename P0 = identity,
0044                  typename P1 = identity)(
0045             requires ((forward_iterator<I0> && sentinel_for<S0, I0>) ||
0046                       (input_iterator<I0> && sized_sentinel_for<S0, I0>)) AND
0047                 ((forward_iterator<I1> && sentinel_for<S1, I1>) ||
0048                  (input_iterator<I1> && sized_sentinel_for<S1, I1>)) AND
0049                 indirectly_comparable<I0, I1, C, P0, P1>)
0050         constexpr bool RANGES_FUNC(ends_with)(I0 begin0,
0051                                               S0 end0,
0052                                               I1 begin1,
0053                                               S1 end1,
0054                                               C pred = C{},
0055                                               P0 proj0 = P0{},
0056                                               P1 proj1 = P1{}) //
0057         {
0058             const auto drop = distance(begin0, end0) - distance(begin1, end1);
0059             if(drop < 0)
0060                 return false;
0061             return equal(next(std::move(begin0), drop),
0062                          std::move(end0),
0063                          std::move(begin1),
0064                          std::move(end1),
0065                          std::move(pred),
0066                          std::move(proj0),
0067                          std::move(proj1));
0068         }
0069 
0070         /// \overload
0071         template(typename Rng0,
0072                  typename Rng1,
0073                  typename C = equal_to,
0074                  typename P0 = identity,
0075                  typename P1 = identity)(
0076             requires (forward_range<Rng0> || (input_range<Rng0> && sized_range<Rng0>)) AND
0077                 (forward_range<Rng1> || (input_range<Rng1> && sized_range<Rng1>)) AND
0078                 indirectly_comparable<iterator_t<Rng0>, iterator_t<Rng1>, C, P0, P1>)
0079         constexpr bool RANGES_FUNC(ends_with)(
0080             Rng0 && rng0, Rng1 && rng1, C pred = C{}, P0 proj0 = P0{}, P1 proj1 = P1{}) //
0081         {
0082             const auto drop = distance(rng0) - distance(rng1);
0083             if(drop < 0)
0084                 return false;
0085             return equal(next(begin(rng0), drop),
0086                          end(rng0),
0087                          begin(rng1),
0088                          end(rng1),
0089                          std::move(pred),
0090                          std::move(proj0),
0091                          std::move(proj1));
0092         }
0093 
0094     RANGES_FUNC_END(ends_with)
0095     /// @}
0096 } // namespace ranges
0097 
0098 #include <range/v3/detail/epilogue.hpp>
0099 
0100 #endif