Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:20

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_NTH_ELEMENT_H
0010 #define _LIBCPP___CXX03___ALGORITHM_RANGES_NTH_ELEMENT_H
0011 
0012 #include <__cxx03/__algorithm/iterator_operations.h>
0013 #include <__cxx03/__algorithm/make_projected.h>
0014 #include <__cxx03/__algorithm/nth_element.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__functional/identity.h>
0017 #include <__cxx03/__functional/invoke.h>
0018 #include <__cxx03/__functional/ranges_operations.h>
0019 #include <__cxx03/__iterator/concepts.h>
0020 #include <__cxx03/__iterator/iterator_traits.h>
0021 #include <__cxx03/__iterator/next.h>
0022 #include <__cxx03/__iterator/projected.h>
0023 #include <__cxx03/__iterator/sortable.h>
0024 #include <__cxx03/__ranges/access.h>
0025 #include <__cxx03/__ranges/concepts.h>
0026 #include <__cxx03/__ranges/dangling.h>
0027 #include <__cxx03/__utility/forward.h>
0028 #include <__cxx03/__utility/move.h>
0029 
0030 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0031 #  pragma GCC system_header
0032 #endif
0033 
0034 _LIBCPP_PUSH_MACROS
0035 #include <__cxx03/__undef_macros>
0036 
0037 #if _LIBCPP_STD_VER >= 20
0038 
0039 _LIBCPP_BEGIN_NAMESPACE_STD
0040 
0041 namespace ranges {
0042 namespace __nth_element {
0043 
0044 struct __fn {
0045   template <class _Iter, class _Sent, class _Comp, class _Proj>
0046   _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
0047   __nth_element_fn_impl(_Iter __first, _Iter __nth, _Sent __last, _Comp& __comp, _Proj& __proj) {
0048     auto __last_iter = ranges::next(__first, __last);
0049 
0050     auto&& __projected_comp = std::__make_projected(__comp, __proj);
0051     std::__nth_element_impl<_RangeAlgPolicy>(std::move(__first), std::move(__nth), __last_iter, __projected_comp);
0052 
0053     return __last_iter;
0054   }
0055 
0056   template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
0057     requires sortable<_Iter, _Comp, _Proj>
0058   _LIBCPP_HIDE_FROM_ABI constexpr _Iter
0059   operator()(_Iter __first, _Iter __nth, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
0060     return __nth_element_fn_impl(std::move(__first), std::move(__nth), std::move(__last), __comp, __proj);
0061   }
0062 
0063   template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
0064     requires sortable<iterator_t<_Range>, _Comp, _Proj>
0065   _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
0066   operator()(_Range&& __r, iterator_t<_Range> __nth, _Comp __comp = {}, _Proj __proj = {}) const {
0067     return __nth_element_fn_impl(ranges::begin(__r), std::move(__nth), ranges::end(__r), __comp, __proj);
0068   }
0069 };
0070 
0071 } // namespace __nth_element
0072 
0073 inline namespace __cpo {
0074 inline constexpr auto nth_element = __nth_element::__fn{};
0075 } // namespace __cpo
0076 } // namespace ranges
0077 
0078 _LIBCPP_END_NAMESPACE_STD
0079 
0080 #endif // _LIBCPP_STD_VER >= 20
0081 
0082 _LIBCPP_POP_MACROS
0083 
0084 #endif // _LIBCPP___CXX03___ALGORITHM_RANGES_NTH_ELEMENT_H