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_COMP_REF_TYPE_H
10 #define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
16 # include <__utility/declval.h>
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #pragma GCC system_header
23 _LIBCPP_BEGIN_NAMESPACE_STD
27 template <class _Compare>
31 _LIBCPP_CONSTEXPR_AFTER_CXX17
32 __debug_less(_Compare& __c) : __comp_(__c) {}
34 template <class _Tp, class _Up>
35 _LIBCPP_CONSTEXPR_AFTER_CXX17
36 bool operator()(const _Tp& __x, const _Up& __y)
38 bool __r = __comp_(__x, __y);
40 __do_compare_assert(0, __y, __x);
44 template <class _Tp, class _Up>
45 _LIBCPP_CONSTEXPR_AFTER_CXX17
46 bool operator()(_Tp& __x, _Up& __y)
48 bool __r = __comp_(__x, __y);
50 __do_compare_assert(0, __y, __x);
54 template <class _LHS, class _RHS>
55 _LIBCPP_CONSTEXPR_AFTER_CXX17
56 inline _LIBCPP_INLINE_VISIBILITY
57 decltype((void)declval<_Compare&>()(
58 declval<_LHS &>(), declval<_RHS &>()))
59 __do_compare_assert(int, _LHS & __l, _RHS & __r) {
60 _LIBCPP_ASSERT(!__comp_(__l, __r),
61 "Comparator does not induce a strict weak ordering");
64 template <class _LHS, class _RHS>
65 _LIBCPP_CONSTEXPR_AFTER_CXX17
66 inline _LIBCPP_INLINE_VISIBILITY
67 void __do_compare_assert(long, _LHS &, _RHS &) {}
70 #endif // _LIBCPP_DEBUG
72 template <class _Comp>
73 struct __comp_ref_type {
74 // Pass the comparator by lvalue reference. Or in debug mode, using a
75 // debugging wrapper that stores a reference.
79 typedef __debug_less<_Comp> type;
83 _LIBCPP_END_NAMESPACE_STD
85 #endif // _LIBCPP___ALGORITHM_COMP_REF_TYPE_H