Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2013-present
0005 //  Copyright Gonzalo Brito Gadeschi 2014
0006 //
0007 //  Use, modification and distribution is subject to the
0008 //  Boost Software License, Version 1.0. (See accompanying
0009 //  file LICENSE_1_0.txt or copy at
0010 //  http://www.boost.org/LICENSE_1_0.txt)
0011 //
0012 // Project home: https://github.com/ericniebler/range-v3
0013 //
0014 // Implementation based on the code in libc++
0015 //   http://http://libcxx.llvm.org/
0016 #ifndef RANGES_V3_ALGORITHM_IS_SORTED_UNTIL_HPP
0017 #define RANGES_V3_ALGORITHM_IS_SORTED_UNTIL_HPP
0018 
0019 #include <range/v3/range_fwd.hpp>
0020 
0021 #include <range/v3/functional/comparisons.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/range/access.hpp>
0026 #include <range/v3/range/concepts.hpp>
0027 #include <range/v3/range/dangling.hpp>
0028 #include <range/v3/range/traits.hpp>
0029 #include <range/v3/utility/static_const.hpp>
0030 
0031 #include <range/v3/detail/prologue.hpp>
0032 
0033 namespace ranges
0034 {
0035     /// \addtogroup group-algorithms
0036     /// @{
0037     RANGES_FUNC_BEGIN(is_sorted_until)
0038         /// \brief template function \c is_sorted_until
0039         ///
0040         /// range-based version of the \c is_sorted_until std algorithm
0041         ///
0042         /// Works on forward_ranges
0043         ///
0044         /// \pre `Rng` is a model of the `forward_range` concept
0045         /// \pre `I` is a model of the `forward_iterator` concept
0046         /// \pre `S` and `I` model the `sentinel_for<S, I>` concept
0047         /// \pre `R` and `projected<I, P>` model the `indirect_strict_weak_order<R,
0048         /// projected<I, P>>` concept
0049         ///
0050         template(typename I, typename S, typename R = less, typename P = identity)(
0051             requires forward_iterator<I> AND sentinel_for<S, I> AND
0052             indirect_strict_weak_order<R, projected<I, P>>)
0053         constexpr I RANGES_FUNC(is_sorted_until)(I first, S last, R pred = R{}, P proj = P{})
0054         {
0055             auto i = first;
0056             if(first != last)
0057             {
0058                 while(++i != last)
0059                 {
0060                     if(invoke(pred, invoke(proj, *i), invoke(proj, *first)))
0061                         return i;
0062                     first = i;
0063                 }
0064             }
0065             return i;
0066         }
0067 
0068         /// \overload
0069         template(typename Rng, typename R = less, typename P = identity)(
0070             requires forward_range<Rng> AND
0071             indirect_strict_weak_order<R, projected<iterator_t<Rng>, P>>)
0072         constexpr borrowed_iterator_t<Rng> //
0073         RANGES_FUNC(is_sorted_until)(Rng && rng, R pred = R{}, P proj = P{})
0074         {
0075             return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
0076         }
0077 
0078     RANGES_FUNC_END(is_sorted_until)
0079 
0080     namespace cpp20
0081     {
0082         using ranges::is_sorted_until;
0083     }
0084     /// @}
0085 } // namespace ranges
0086 
0087 #include <range/v3/detail/epilogue.hpp>
0088 
0089 #endif