1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
10 #define _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
12 #include <__cxx03/__algorithm/iterator_operations.h>
13 #include <__cxx03/__algorithm/make_heap.h>
14 #include <__cxx03/__algorithm/make_projected.h>
15 #include <__cxx03/__concepts/same_as.h>
16 #include <__cxx03/__config>
17 #include <__cxx03/__functional/identity.h>
18 #include <__cxx03/__functional/invoke.h>
19 #include <__cxx03/__functional/ranges_operations.h>
20 #include <__cxx03/__iterator/concepts.h>
21 #include <__cxx03/__iterator/iterator_traits.h>
22 #include <__cxx03/__iterator/next.h>
23 #include <__cxx03/__iterator/projected.h>
24 #include <__cxx03/__iterator/sortable.h>
25 #include <__cxx03/__ranges/access.h>
26 #include <__cxx03/__ranges/concepts.h>
27 #include <__cxx03/__ranges/dangling.h>
28 #include <__cxx03/__utility/forward.h>
29 #include <__cxx03/__utility/move.h>
31 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32 # pragma GCC system_header
36 #include <__cxx03/__undef_macros>
38 #if _LIBCPP_STD_VER >= 20
40 _LIBCPP_BEGIN_NAMESPACE_STD
43 namespace __make_heap
{
46 template <class _Iter
, class _Sent
, class _Comp
, class _Proj
>
47 _LIBCPP_HIDE_FROM_ABI
constexpr static _Iter
48 __make_heap_fn_impl(_Iter __first
, _Sent __last
, _Comp
& __comp
, _Proj
& __proj
) {
49 auto __last_iter
= ranges::next(__first
, __last
);
51 auto&& __projected_comp
= std::__make_projected(__comp
, __proj
);
52 std::__make_heap
<_RangeAlgPolicy
>(std::move(__first
), __last_iter
, __projected_comp
);
57 template <random_access_iterator _Iter
, sentinel_for
<_Iter
> _Sent
, class _Comp
= ranges::less
, class _Proj
= identity
>
58 requires sortable
<_Iter
, _Comp
, _Proj
>
59 _LIBCPP_HIDE_FROM_ABI
constexpr _Iter
60 operator()(_Iter __first
, _Sent __last
, _Comp __comp
= {}, _Proj __proj
= {}) const {
61 return __make_heap_fn_impl(std::move(__first
), std::move(__last
), __comp
, __proj
);
64 template <random_access_range _Range
, class _Comp
= ranges::less
, class _Proj
= identity
>
65 requires sortable
<iterator_t
<_Range
>, _Comp
, _Proj
>
66 _LIBCPP_HIDE_FROM_ABI
constexpr borrowed_iterator_t
<_Range
>
67 operator()(_Range
&& __r
, _Comp __comp
= {}, _Proj __proj
= {}) const {
68 return __make_heap_fn_impl(ranges::begin(__r
), ranges::end(__r
), __comp
, __proj
);
72 } // namespace __make_heap
74 inline namespace __cpo
{
75 inline constexpr auto make_heap
= __make_heap::__fn
{};
79 _LIBCPP_END_NAMESPACE_STD
81 #endif // _LIBCPP_STD_VER >= 20
85 #endif // _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H