stl_relops.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // std::rel_ops implementation -*- C++ -*-
  2. // Copyright (C) 2001-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the, 2009 Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /*
  21. *
  22. * Copyright (c) 1994
  23. * Hewlett-Packard Company
  24. *
  25. * Permission to use, copy, modify, distribute and sell this software
  26. * and its documentation for any purpose is hereby granted without fee,
  27. * provided that the above copyright notice appear in all copies and
  28. * that both that copyright notice and this permission notice appear
  29. * in supporting documentation. Hewlett-Packard Company makes no
  30. * representations about the suitability of this software for any
  31. * purpose. It is provided "as is" without express or implied warranty.
  32. *
  33. * Copyright (c) 1996,1997
  34. * Silicon Graphics
  35. *
  36. * Permission to use, copy, modify, distribute and sell this software
  37. * and its documentation for any purpose is hereby granted without fee,
  38. * provided that the above copyright notice appear in all copies and
  39. * that both that copyright notice and this permission notice appear
  40. * in supporting documentation. Silicon Graphics makes no
  41. * representations about the suitability of this software for any
  42. * purpose. It is provided "as is" without express or implied warranty.
  43. *
  44. */
  45. /** @file bits/stl_relops.h
  46. * This is an internal header file, included by other library headers.
  47. * Do not attempt to use it directly. @headername{utility}
  48. *
  49. * This file is only included by `<utility>`, which is required by the
  50. * standard to define namespace `rel_ops` and its contents.
  51. */
  52. #ifndef _STL_RELOPS_H
  53. #define _STL_RELOPS_H 1
  54. namespace std _GLIBCXX_VISIBILITY(default)
  55. {
  56. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  57. namespace rel_ops
  58. {
  59. /** @namespace std::rel_ops
  60. * @brief The generated relational operators are sequestered here.
  61. *
  62. * Libstdc++ headers must not use the contents of `rel_ops`.
  63. * User code should also avoid them, because unconstrained function
  64. * templates are too greedy and can easily cause ambiguities.
  65. *
  66. * C++20 default comparisons are a better solution.
  67. */
  68. /**
  69. * @brief Defines @c != for arbitrary types, in terms of @c ==.
  70. * @param __x A thing.
  71. * @param __y Another thing.
  72. * @return __x != __y
  73. *
  74. * This function uses @c == to determine its result.
  75. */
  76. template <class _Tp>
  77. inline bool
  78. operator!=(const _Tp& __x, const _Tp& __y)
  79. { return !(__x == __y); }
  80. /**
  81. * @brief Defines @c > for arbitrary types, in terms of @c <.
  82. * @param __x A thing.
  83. * @param __y Another thing.
  84. * @return __x > __y
  85. *
  86. * This function uses @c < to determine its result.
  87. */
  88. template <class _Tp>
  89. inline bool
  90. operator>(const _Tp& __x, const _Tp& __y)
  91. { return __y < __x; }
  92. /**
  93. * @brief Defines @c <= for arbitrary types, in terms of @c <.
  94. * @param __x A thing.
  95. * @param __y Another thing.
  96. * @return __x <= __y
  97. *
  98. * This function uses @c < to determine its result.
  99. */
  100. template <class _Tp>
  101. inline bool
  102. operator<=(const _Tp& __x, const _Tp& __y)
  103. { return !(__y < __x); }
  104. /**
  105. * @brief Defines @c >= for arbitrary types, in terms of @c <.
  106. * @param __x A thing.
  107. * @param __y Another thing.
  108. * @return __x >= __y
  109. *
  110. * This function uses @c < to determine its result.
  111. */
  112. template <class _Tp>
  113. inline bool
  114. operator>=(const _Tp& __x, const _Tp& __y)
  115. { return !(__x < __y); }
  116. } // namespace rel_ops
  117. _GLIBCXX_END_NAMESPACE_VERSION
  118. } // namespace std
  119. #endif /* _STL_RELOPS_H */