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___COMPARE_SYNTH_THREE_WAY_H
10 #define _LIBCPP___COMPARE_SYNTH_THREE_WAY_H
11 
12 #include <__compare/ordering.h>
13 #include <__compare/three_way_comparable.h>
14 #include <__concepts/boolean_testable.h>
15 #include <__config>
16 #include <__utility/declval.h>
17 
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #pragma GCC system_header
20 #endif
21 
22 _LIBCPP_BEGIN_NAMESPACE_STD
23 
24 #if !defined(_LIBCPP_HAS_NO_CONCEPTS)
25 
26 // [expos.only.func]
27 
28 _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
29   []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
30     requires requires {
31       { __t < __u } -> __boolean_testable;
32       { __u < __t } -> __boolean_testable;
33     }
34   {
35     if constexpr (three_way_comparable_with<_Tp, _Up>) {
36       return __t <=> __u;
37     } else {
38       if (__t < __u) return weak_ordering::less;
39       if (__u < __t) return weak_ordering::greater;
40       return weak_ordering::equivalent;
41     }
42   };
43 
44 template <class _Tp, class _Up = _Tp>
45 using __synth_three_way_result = decltype(__synth_three_way(declval<_Tp&>(), declval<_Up&>()));
46 
47 #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
48 
49 _LIBCPP_END_NAMESPACE_STD
50 
51 #endif // _LIBCPP___COMPARE_SYNTH_THREE_WAY_H
52