]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/libcxx/include/__algorithm/comp_ref_type.h
Merge llvm-project main llvmorg-14-init-10186-gff7f2cfa959b
[FreeBSD/FreeBSD.git] / contrib / llvm-project / libcxx / include / __algorithm / comp_ref_type.h
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 //===----------------------------------------------------------------------===//
8
9 #ifndef _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
10 #define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
11
12 #include <__config>
13
14 #ifdef _LIBCPP_DEBUG
15 #  include <__debug>
16 #  include <__utility/declval.h>
17 #endif
18
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #pragma GCC system_header
21 #endif
22
23 _LIBCPP_BEGIN_NAMESPACE_STD
24
25 #ifdef _LIBCPP_DEBUG
26
27 template <class _Compare>
28 struct __debug_less
29 {
30     _Compare &__comp_;
31     _LIBCPP_CONSTEXPR_AFTER_CXX17
32     __debug_less(_Compare& __c) : __comp_(__c) {}
33
34     template <class _Tp, class _Up>
35     _LIBCPP_CONSTEXPR_AFTER_CXX17
36     bool operator()(const _Tp& __x,  const _Up& __y)
37     {
38         bool __r = __comp_(__x, __y);
39         if (__r)
40             __do_compare_assert(0, __y, __x);
41         return __r;
42     }
43
44     template <class _Tp, class _Up>
45     _LIBCPP_CONSTEXPR_AFTER_CXX17
46     bool operator()(_Tp& __x,  _Up& __y)
47     {
48         bool __r = __comp_(__x, __y);
49         if (__r)
50             __do_compare_assert(0, __y, __x);
51         return __r;
52     }
53
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");
62     }
63
64     template <class _LHS, class _RHS>
65     _LIBCPP_CONSTEXPR_AFTER_CXX17
66     inline _LIBCPP_INLINE_VISIBILITY
67     void __do_compare_assert(long, _LHS &, _RHS &) {}
68 };
69
70 #endif // _LIBCPP_DEBUG
71
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.
76 #ifndef _LIBCPP_DEBUG
77   typedef _Comp& type;
78 #else
79   typedef __debug_less<_Comp> type;
80 #endif
81 };
82
83 _LIBCPP_END_NAMESPACE_STD
84
85 #endif // _LIBCPP___ALGORITHM_COMP_REF_TYPE_H