1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H 10 #define _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H 11 12 #include <__algorithm/ranges_is_sorted_until.h> 13 #include <__config> 14 #include <__functional/identity.h> 15 #include <__functional/ranges_operations.h> 16 #include <__iterator/concepts.h> 17 #include <__iterator/projected.h> 18 #include <__ranges/access.h> 19 #include <__ranges/concepts.h> 20 #include <__utility/move.h> 21 22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 23 # pragma GCC system_header 24 #endif 25 26 _LIBCPP_PUSH_MACROS 27 #include <__undef_macros> 28 29 #if _LIBCPP_STD_VER >= 20 30 31 _LIBCPP_BEGIN_NAMESPACE_STD 32 33 namespace ranges { 34 namespace __is_sorted { 35 struct __fn { 36 template <forward_iterator _Iter, 37 sentinel_for<_Iter> _Sent, 38 class _Proj = identity, 39 indirect_strict_weak_order<projected<_Iter, _Proj>> _Comp = ranges::less> 40 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator__fn41 operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { 42 return ranges::__is_sorted_until_impl(std::move(__first), __last, __comp, __proj) == __last; 43 } 44 45 template <forward_range _Range, 46 class _Proj = identity, 47 indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less> 48 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator__fn49 operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { 50 auto __last = ranges::end(__range); 51 return ranges::__is_sorted_until_impl(ranges::begin(__range), __last, __comp, __proj) == __last; 52 } 53 }; 54 } // namespace __is_sorted 55 56 inline namespace __cpo { 57 inline constexpr auto is_sorted = __is_sorted::__fn{}; 58 } // namespace __cpo 59 } // namespace ranges 60 61 _LIBCPP_END_NAMESPACE_STD 62 63 #endif // _LIBCPP_STD_VER >= 20 64 65 _LIBCPP_POP_MACROS 66 67 #endif // _LIBCPP__ALGORITHM_RANGES_IS_SORTED_H 68