Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / include / __algorithm / ranges_make_heap.h
blob97148f77b41819c7e2b9205a5f6b4313d0d28dd5
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 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
10 #define _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H
12 #include <__algorithm/iterator_operations.h>
13 #include <__algorithm/make_heap.h>
14 #include <__algorithm/make_projected.h>
15 #include <__concepts/same_as.h>
16 #include <__config>
17 #include <__functional/identity.h>
18 #include <__functional/invoke.h>
19 #include <__functional/ranges_operations.h>
20 #include <__iterator/concepts.h>
21 #include <__iterator/iterator_traits.h>
22 #include <__iterator/next.h>
23 #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>
31 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32 # pragma GCC system_header
33 #endif
35 _LIBCPP_PUSH_MACROS
36 #include <__undef_macros>
38 #if _LIBCPP_STD_VER >= 20
40 _LIBCPP_BEGIN_NAMESPACE_STD
42 namespace ranges {
43 struct __make_heap {
44 template <class _Iter, class _Sent, class _Comp, class _Proj>
45 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
46 __make_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
47 auto __last_iter = ranges::next(__first, __last);
49 auto&& __projected_comp = std::__make_projected(__comp, __proj);
50 std::__make_heap<_RangeAlgPolicy>(std::move(__first), __last_iter, __projected_comp);
52 return __last_iter;
55 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
56 requires sortable<_Iter, _Comp, _Proj>
57 _LIBCPP_HIDE_FROM_ABI constexpr _Iter
58 operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
59 return __make_heap_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
62 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
63 requires sortable<iterator_t<_Range>, _Comp, _Proj>
64 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
65 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
66 return __make_heap_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
70 inline namespace __cpo {
71 inline constexpr auto make_heap = __make_heap{};
72 } // namespace __cpo
73 } // namespace ranges
75 _LIBCPP_END_NAMESPACE_STD
77 #endif // _LIBCPP_STD_VER >= 20
79 _LIBCPP_POP_MACROS
81 #endif // _LIBCPP___ALGORITHM_RANGES_MAKE_HEAP_H