comp.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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___ALGORITHM_COMP_H
  9. #define _LIBCPP___ALGORITHM_COMP_H
  10. #include <__config>
  11. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  12. # pragma GCC system_header
  13. #endif
  14. _LIBCPP_BEGIN_NAMESPACE_STD
  15. // I'd like to replace these with _VSTD::equal_to<void>, but can't because:
  16. // * That only works with C++14 and later, and
  17. // * We haven't included <functional> here.
  18. template <class _T1, class _T2 = _T1>
  19. struct __equal_to
  20. {
  21. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
  22. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T2& __y) const {return __x == __y;}
  23. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T1& __y) const {return __x == __y;}
  24. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T2& __y) const {return __x == __y;}
  25. };
  26. template <class _T1>
  27. struct __equal_to<_T1, _T1>
  28. {
  29. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  30. bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
  31. };
  32. template <class _T1>
  33. struct __equal_to<const _T1, _T1>
  34. {
  35. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  36. bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
  37. };
  38. template <class _T1>
  39. struct __equal_to<_T1, const _T1>
  40. {
  41. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  42. bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
  43. };
  44. template <class _T1, class _T2 = _T1>
  45. struct __less
  46. {
  47. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  48. bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
  49. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  50. bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;}
  51. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  52. bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;}
  53. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  54. bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;}
  55. };
  56. template <class _T1>
  57. struct __less<_T1, _T1>
  58. {
  59. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  60. bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
  61. };
  62. template <class _T1>
  63. struct __less<const _T1, _T1>
  64. {
  65. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  66. bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
  67. };
  68. template <class _T1>
  69. struct __less<_T1, const _T1>
  70. {
  71. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  72. bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
  73. };
  74. _LIBCPP_END_NAMESPACE_STD
  75. #endif // _LIBCPP___ALGORITHM_COMP_H