Leaked source code of windows server 2003
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.

171 lines
4.6 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. _Ty1 first; // the first stored value
  43. _Ty2 second; // the second stored value
  44. };
  45. // pair TEMPLATE FUNCTIONS
  46. template<class _Ty1,
  47. class _Ty2> inline
  48. bool __cdecl operator==(const pair<_Ty1, _Ty2>& _Left,
  49. const pair<_Ty1, _Ty2>& _Right)
  50. { // test for pair equality
  51. return (_Left.first == _Right.first && _Left.second == _Right.second);
  52. }
  53. template<class _Ty1,
  54. class _Ty2> inline
  55. bool __cdecl operator!=(const pair<_Ty1, _Ty2>& _Left,
  56. const pair<_Ty1, _Ty2>& _Right)
  57. { // test for pair inequality
  58. return (!(_Left == _Right));
  59. }
  60. template<class _Ty1,
  61. class _Ty2> inline
  62. bool __cdecl operator<(const pair<_Ty1, _Ty2>& _Left,
  63. const pair<_Ty1, _Ty2>& _Right)
  64. { // test if _Left < _Right for pairs
  65. return (_Left.first < _Right.first ||
  66. !(_Right.first < _Left.first) && _Left.second < _Right.second);
  67. }
  68. template<class _Ty1,
  69. class _Ty2> inline
  70. bool __cdecl operator>(const pair<_Ty1, _Ty2>& _Left,
  71. const pair<_Ty1, _Ty2>& _Right)
  72. { // test if _Left > _Right for pairs
  73. return (_Right < _Left);
  74. }
  75. template<class _Ty1,
  76. class _Ty2> inline
  77. bool __cdecl operator<=(const pair<_Ty1, _Ty2>& _Left,
  78. const pair<_Ty1, _Ty2>& _Right)
  79. { // test if _Left <= _Right for pairs
  80. return (!(_Right < _Left));
  81. }
  82. template<class _Ty1,
  83. class _Ty2> inline
  84. bool __cdecl operator>=(const pair<_Ty1, _Ty2>& _Left,
  85. const pair<_Ty1, _Ty2>& _Right)
  86. { // test if _Left >= _Right for pairs
  87. return (!(_Left < _Right));
  88. }
  89. template<class _Ty1,
  90. class _Ty2> inline
  91. pair<_Ty1, _Ty2> __cdecl make_pair(_Ty1 _Val1, _Ty2 _Val2)
  92. { // return pair composed from arguments
  93. return (pair<_Ty1, _Ty2>(_Val1, _Val2));
  94. }
  95. template<class _Ty1,
  96. class _Ty2> inline
  97. void swap(pair<_Ty1, _Ty2>& _Left, pair<_Ty1, _Ty2>& _Right)
  98. { // swap _Left and _Right pairs
  99. _Left.swap(_Right);
  100. }
  101. // TEMPLATE OPERATORS
  102. namespace rel_ops
  103. { // nested namespace to hide relational operators from std
  104. template<class _Ty> inline
  105. bool __cdecl operator!=(const _Ty& _Left, const _Ty& _Right)
  106. { // test for inequality, in terms of equality
  107. return (!(_Left == _Right));
  108. }
  109. template<class _Ty> inline
  110. bool __cdecl operator>(const _Ty& _Left, const _Ty& _Right)
  111. { // test if _Left > _Right, in terms of operator<
  112. return (_Right < _Left);
  113. }
  114. template<class _Ty> inline
  115. bool __cdecl operator<=(const _Ty& _Left, const _Ty& _Right)
  116. { // test if _Left <= _Right, in terms of operator<
  117. return (!(_Right < _Left));
  118. }
  119. template<class _Ty> inline
  120. bool __cdecl operator>=(const _Ty& _Left, const _Ty& _Right)
  121. { // test if _Left >= _Right, in terms of operator<
  122. return (!(_Left < _Right));
  123. }
  124. }
  125. _STD_END
  126. #pragma warning(pop)
  127. #pragma pack(pop)
  128. #endif /* _UTILITY_ */
  129. /*
  130. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  131. * Consult your license regarding permissions and restrictions.
  132. */
  133. /*
  134. * This file is derived from software bearing the following
  135. * restrictions:
  136. *
  137. * Copyright (c) 1994
  138. * Hewlett-Packard Company
  139. *
  140. * Permission to use, copy, modify, distribute and sell this
  141. * software and its documentation for any purpose is hereby
  142. * granted without fee, provided that the above copyright notice
  143. * appear in all copies and that both that copyright notice and
  144. * this permission notice appear in supporting documentation.
  145. * Hewlett-Packard Company makes no representations about the
  146. * suitability of this software for any purpose. It is provided
  147. * "as is" without express or implied warranty.
  148. V3.10:0009 */