150472Speter//===----------------------------------------------------------------------===//
23515Sache//
3217309Snwhitehorn// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4156813Sru// See https://llvm.org/LICENSE.txt for license information.
5217309Snwhitehorn// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6252129Sbapt//
7251843Sbapt//===----------------------------------------------------------------------===//
8251843Sbapt
9251843Sbapt#ifndef _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
10251843Sbapt#define _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
11251843Sbapt
12251843Sbapt#include <__algorithm/iterator_operations.h>
13217309Snwhitehorn#include <__algorithm/make_heap.h>
14217309Snwhitehorn#include <__algorithm/make_projected.h>
1512983Sjkh#include <__concepts/same_as.h>
16275040Sdteske#include <__config>
17275040Sdteske#include <__functional/identity.h>
18275040Sdteske#include <__functional/invoke.h>
19251843Sbapt#include <__functional/ranges_operations.h>
20217309Snwhitehorn#include <__iterator/concepts.h>
21251845Sbapt#include <__iterator/iterator_traits.h>
223515Sache#include <__iterator/next.h>
233515Sache#include <__iterator/projected.h>
24#include <__iterator/sortable.h>
25#include <__ranges/access.h>
26#include <__ranges/concepts.h>
27#include <__ranges/dangling.h>
28#include <__utility/forward.h>
29#include <__utility/move.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32#  pragma GCC system_header
33#endif
34
35#if _LIBCPP_STD_VER > 17
36
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40namespace __make_heap {
41
42struct __fn {
43  template <class _Iter, class _Sent, class _Comp, class _Proj>
44  _LIBCPP_HIDE_FROM_ABI constexpr static
45  _Iter __make_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
46    auto __last_iter = ranges::next(__first, __last);
47
48    auto&& __projected_comp = std::__make_projected(__comp, __proj);
49    std::__make_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp);
50
51    return __last_iter;
52  }
53
54  template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
55    requires sortable<_Iter, _Comp, _Proj>
56  _LIBCPP_HIDE_FROM_ABI constexpr
57  _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
58    return __make_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
59  }
60
61  template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
62    requires sortable<iterator_t<_Range>, _Comp, _Proj>
63  _LIBCPP_HIDE_FROM_ABI constexpr
64  borrowed_iterator_t<_Range> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
65    return __make_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
66  }
67};
68
69} // namespace __make_heap
70
71inline namespace __cpo {
72  inline constexpr auto make_heap = __make_heap::__fn{};
73} // namespace __cpo
74} // namespace ranges
75
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP_STD_VER > 17
79
80#endif // _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
81