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_HPP
0017 #define RANGES_V3_ALGORITHM_IS_SORTED_HPP
0018 
0019 #include <utility>
0020 
0021 #include <range/v3/range_fwd.hpp>
0022 
0023 #include <range/v3/algorithm/is_sorted_until.hpp>
0024 #include <range/v3/functional/comparisons.hpp>
0025 #include <range/v3/functional/identity.hpp>
0026 #include <range/v3/iterator/concepts.hpp>
0027 #include <range/v3/utility/static_const.hpp>
0028 
0029 #include <range/v3/detail/prologue.hpp>
0030 
0031 namespace ranges
0032 {
0033     /// \addtogroup group-algorithms
0034     /// @{
0035     RANGES_FUNC_BEGIN(is_sorted)
0036         /// \brief template function \c is_sorted
0037         ///
0038         /// range-based version of the \c is_sorted std algorithm
0039         ///
0040         /// Works on forward_ranges
0041         ///
0042         /// \pre `Rng` is a model of the `forward_range` concept
0043         /// \pre `I` is a model of the `forward_iterator` concept
0044         /// \pre `S` and `I` model the `sentinel_for<S, I>` concept
0045         /// \pre `R` and `projected<I, P>` model the `indirect_strict_weak_order<R,
0046         /// projected<I, P>>` concept
0047         ///
0048         template(typename I, typename S, typename R = less, typename P = identity)(
0049             requires forward_iterator<I> AND sentinel_for<S, I> AND
0050             indirect_strict_weak_order<R, projected<I, P>>)
0051         constexpr bool RANGES_FUNC(is_sorted)(I first, S last, R rel = R{}, P proj = P{})
0052         {
0053             return is_sorted_until(
0054                        std::move(first), last, std::move(rel), std::move(proj)) == last;
0055         }
0056 
0057         /// \overload
0058         template(typename Rng, typename R = less, typename P = identity)(
0059             requires forward_range<Rng> AND
0060             indirect_strict_weak_order<R, projected<iterator_t<Rng>, P>>)
0061         constexpr bool RANGES_FUNC(is_sorted)(Rng && rng, R rel = R{}, P proj = P{}) //
0062         {
0063             return (*this)(begin(rng), end(rng), std::move(rel), std::move(proj));
0064         }
0065 
0066     RANGES_FUNC_END(is_sorted)
0067 
0068     namespace cpp20
0069     {
0070         using ranges::is_sorted;
0071     }
0072     /// @}
0073 } // namespace ranges
0074 
0075 #include <range/v3/detail/epilogue.hpp>
0076 
0077 #endif