Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.3 KiB

  1. // utility standard header
  2. #pragma once
  3. #ifndef _UTILITY_
  4. #define _UTILITY_
  5. #include <iosfwd>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. _STD_BEGIN
  9. // TEMPLATE FUNCTION swap (from <algorithm>)
  10. template<class _Ty> inline
  11. void swap(_Ty& _Left, _Ty& _Right)
  12. { // exchange values stored at _Left and _Right
  13. _Ty _Tmp = _Left;
  14. _Left = _Right, _Right = _Tmp;
  15. }
  16. // TEMPLATE STRUCT pair
  17. template<class _Ty1,
  18. class _Ty2> struct pair
  19. { // store a pair of values
  20. typedef pair<_Ty1, _Ty2> _Myt;
  21. typedef _Ty1 first_type;
  22. typedef _Ty2 second_type;
  23. pair()
  24. : first(_Ty1()), second(_Ty2())
  25. { // construct from defaults
  26. }
  27. pair(const _Ty1& _Val1, const _Ty2& _Val2)
  28. : first(_Val1), second(_Val2)
  29. { // construct from specified values
  30. }
  31. template<class _Other1,
  32. class _Other2>
  33. pair(const pair<_Other1, _Other2>& _Right)
  34. : first(_Right.first), second(_Right.second)
  35. { // construct from compatible pair
  36. }
  37. void swap(_Myt& _Right)
  38. { // exchange contents with _Right
  39. std::swap(first, _Right.first);
  40. std::swap(second, _Right.second);
  41. }
  42. friend void swap(_Myt& _Left, _Myt& _Right)
  43. { // swap _Left and _Right deques
  44. _Left.swap(_Right);
  45. }
  46. _Ty1 first; // the first stored value
  47. _Ty2 second; // the second stored value
  48. };
  49. // pair TEMPLATE OPERATORS
  50. template<class _Ty1,
  51. class _Ty2> inline
  52. bool __cdecl operator==(const pair<_Ty1, _Ty2>& _Left,
  53. const pair<_Ty1, _Ty2>& _Right)
  54. { // test for pair equality
  55. return (_Left.first == _Right.first && _Left.second == _Right.second);
  56. }
  57. template<class _Ty1,
  58. class _Ty2> inline
  59. bool __cdecl operator!=(const pair<_Ty1, _Ty2>& _Left,
  60. const pair<_Ty1, _Ty2>& _Right)
  61. { // test for pair inequality
  62. return (!(_Left == _Right));
  63. }
  64. template<class _Ty1,
  65. class _Ty2> inline
  66. bool __cdecl operator<(const pair<_Ty1, _Ty2>& _Left,
  67. const pair<_Ty1, _Ty2>& _Right)
  68. { // test if _Left < _Right for pairs
  69. return (_Left.first < _Right.first ||
  70. !(_Right.first < _Left.first) && _Left.second < _Right.second);
  71. }
  72. template<class _Ty1,
  73. class _Ty2> inline
  74. bool __cdecl operator>(const pair<_Ty1, _Ty2>& _Left,
  75. const pair<_Ty1, _Ty2>& _Right)
  76. { // test if _Left > _Right for pairs
  77. return (_Right < _Left);
  78. }
  79. template<class _Ty1,
  80. class _Ty2> inline
  81. bool __cdecl operator<=(const pair<_Ty1, _Ty2>& _Left,
  82. const pair<_Ty1, _Ty2>& _Right)
  83. { // test if _Left <= _Right for pairs
  84. return (!(_Right < _Left));
  85. }
  86. template<class _Ty1,
  87. class _Ty2> inline
  88. bool __cdecl operator>=(const pair<_Ty1, _Ty2>& _Left,
  89. const pair<_Ty1, _Ty2>& _Right)
  90. { // test if _Left >= _Right for pairs
  91. return (!(_Left < _Right));
  92. }
  93. template<class _Ty1,
  94. class _Ty2> inline
  95. pair<_Ty1, _Ty2> __cdecl make_pair(_Ty1 _Val1, _Ty2 _Val2)
  96. { // return pair composed from arguments
  97. return (pair<_Ty1, _Ty2>(_Val1, _Val2));
  98. }
  99. // TEMPLATE OPERATORS
  100. namespace rel_ops
  101. { // nested namespace to hide relational operators from std
  102. template<class _Ty> inline
  103. bool __cdecl operator!=(const _Ty& _Left, const _Ty& _Right)
  104. { // test for inequality, in terms of equality
  105. return (!(_Left == _Right));
  106. }
  107. template<class _Ty> inline
  108. bool __cdecl operator>(const _Ty& _Left, const _Ty& _Right)
  109. { // test if _Left > _Right, in terms of operator<
  110. return (_Right < _Left);
  111. }
  112. template<class _Ty> inline
  113. bool __cdecl operator<=(const _Ty& _Left, const _Ty& _Right)
  114. { // test if _Left <= _Right, in terms of operator<
  115. return (!(_Right < _Left));
  116. }
  117. template<class _Ty> inline
  118. bool __cdecl operator>=(const _Ty& _Left, const _Ty& _Right)
  119. { // test if _Left >= _Right, in terms of operator<
  120. return (!(_Left < _Right));
  121. }
  122. }
  123. _STD_END
  124. #pragma warning(pop)
  125. #pragma pack(pop)
  126. #endif /* _UTILITY_ */
  127. /*
  128. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  129. * Consult your license regarding permissions and restrictions.
  130. */
  131. /*
  132. * This file is derived from software bearing the following
  133. * restrictions:
  134. *
  135. * Copyright (c) 1994
  136. * Hewlett-Packard Company
  137. *
  138. * Permission to use, copy, modify, distribute and sell this
  139. * software and its documentation for any purpose is hereby
  140. * granted without fee, provided that the above copyright notice
  141. * appear in all copies and that both that copyright notice and
  142. * this permission notice appear in supporting documentation.
  143. * Hewlett-Packard Company makes no representations about the
  144. * suitability of this software for any purpose. It is provided
  145. * "as is" without express or implied warranty.
  146. V3.10:0009 */