equality_comparable.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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___CONCEPTS_EQUALITY_COMPARABLE_H
  9. #define _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H
  10. #include <__concepts/boolean_testable.h>
  11. #include <__concepts/common_reference_with.h>
  12. #include <__config>
  13. #include <__type_traits/common_reference.h>
  14. #include <__type_traits/make_const_lvalue_ref.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 >= 20
  20. // [concept.equalitycomparable]
  21. template <class _Tp, class _Up>
  22. concept __weakly_equality_comparable_with =
  23. requires(__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
  24. { __t == __u } -> __boolean_testable;
  25. { __t != __u } -> __boolean_testable;
  26. { __u == __t } -> __boolean_testable;
  27. { __u != __t } -> __boolean_testable;
  28. };
  29. template <class _Tp>
  30. concept equality_comparable = __weakly_equality_comparable_with<_Tp, _Tp>;
  31. // clang-format off
  32. template <class _Tp, class _Up>
  33. concept equality_comparable_with =
  34. equality_comparable<_Tp> && equality_comparable<_Up> &&
  35. common_reference_with<__make_const_lvalue_ref<_Tp>, __make_const_lvalue_ref<_Up>> &&
  36. equality_comparable<
  37. common_reference_t<
  38. __make_const_lvalue_ref<_Tp>,
  39. __make_const_lvalue_ref<_Up>>> &&
  40. __weakly_equality_comparable_with<_Tp, _Up>;
  41. // clang-format on
  42. #endif // _LIBCPP_STD_VER >= 20
  43. _LIBCPP_END_NAMESPACE_STD
  44. #endif // _LIBCPP___CONCEPTS_EQUALITY_COMPARABLE_H