synth_three_way.h 1.5 KB

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