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.

160 lines
4.1 KiB

  1. #pragma once
  2. #ifndef _STLXUTIL_H_
  3. #define _STLXUTIL_H_
  4. //#include <utility>
  5. #include <stlutil.h>
  6. #ifdef _MSC_VER
  7. #pragma pack(push,8)
  8. #endif /* _MSC_VER */
  9. _STD_BEGIN
  10. // TEMPLATE FUNCTION copy
  11. template<class _II, class _OI> inline
  12. _OI copy(_II _F, _II _L, _OI _X)
  13. {
  14. for (; _F != _L; ++_X, ++_F)
  15. *_X = *_F;
  16. return (_X);
  17. }
  18. // TEMPLATE FUNCTION copy_backward
  19. template<class _BI1, class _BI2> inline
  20. _BI2 copy_backward(_BI1 _F, _BI1 _L, _BI2 _X)
  21. {
  22. while (_F != _L)
  23. *--_X = *--_L;
  24. return (_X);
  25. }
  26. // TEMPLATE FUNCTION equal
  27. template<class _II1, class _II2> inline
  28. bool equal(_II1 _F, _II1 _L, _II2 _X)
  29. {
  30. return (mismatch(_F, _L, _X).first == _L);
  31. }
  32. // TEMPLATE FUNCTION equal WITH PRED
  33. template<class _II1, class _II2, class _Pr> inline
  34. bool equal(_II1 _F, _II1 _L, _II2 _X, _Pr _P)
  35. {
  36. return (mismatch(_F, _L, _X, _P).first == _L);
  37. }
  38. // TEMPLATE FUNCTION fill
  39. template<class _FI, class _Ty> inline
  40. void fill(_FI _F, _FI _L, const _Ty& _X)
  41. {
  42. for (; _F != _L; ++_F)
  43. *_F = _X;
  44. }
  45. // TEMPLATE FUNCTION fill_n
  46. template<class _OI, class _Sz, class _Ty> inline
  47. void fill_n(_OI _F, _Sz _N, const _Ty& _X)
  48. {
  49. for (; 0 < _N; --_N, ++_F)
  50. *_F = _X;
  51. }
  52. // TEMPLATE FUNCTION lexicographical_compare
  53. template<class _II1, class _II2> inline
  54. bool lexicographical_compare(_II1 _F1, _II1 _L1,
  55. _II2 _F2, _II2 _L2)
  56. {
  57. for (; _F1 != _L1 && _F2 != _L2; ++_F1, ++_F2)
  58. if (*_F1 < *_F2)
  59. return (true);
  60. else if (*_F2 < *_F1)
  61. return (false);
  62. return (_F1 == _L1 && _F2 != _L2);
  63. }
  64. // TEMPLATE FUNCTION lexicographical_compare WITH PRED
  65. template<class _II1, class _II2, class _Pr> inline
  66. bool lexicographical_compare(_II1 _F1, _II1 _L1,
  67. _II2 _F2, _II2 _L2, _Pr _P)
  68. {
  69. for (; _F1 != _L1 && _F2 != _L2; ++_F1, ++_F2)
  70. if (_P(*_F1, *_F2))
  71. return (true);
  72. else if (_P(*_F2, *_F1))
  73. return (false);
  74. return (_F1 == _L1 && _F2 != _L2);
  75. }
  76. // TEMPLATE FUNCTION max
  77. #ifndef _MAX
  78. #define _MAX _cpp_max
  79. #define _MIN _cpp_min
  80. #endif
  81. template<class _Ty> inline
  82. const _Ty& _cpp_max(const _Ty& _X, const _Ty& _Y)
  83. {
  84. return (_X < _Y ? _Y : _X);
  85. }
  86. // TEMPLATE FUNCTION max WITH PRED
  87. template<class _Ty, class _Pr> inline
  88. const _Ty& _cpp_max(const _Ty& _X, const _Ty& _Y, _Pr _P)
  89. {
  90. return (_P(_X, _Y) ? _Y : _X);
  91. }
  92. // TEMPLATE FUNCTION min
  93. template<class _Ty> inline
  94. const _Ty& _cpp_min(const _Ty& _X, const _Ty& _Y)
  95. {
  96. return (_Y < _X ? _Y : _X);
  97. }
  98. // TEMPLATE FUNCTION min WITH PRED
  99. template<class _Ty, class _Pr> inline
  100. const _Ty& _cpp_min(const _Ty& _X, const _Ty& _Y, _Pr _P)
  101. {
  102. return (_P(_Y, _X) ? _Y : _X);
  103. }
  104. // TEMPLATE FUNCTION mismatch
  105. template<class _II1, class _II2> inline
  106. pair<_II1, _II2> mismatch(_II1 _F, _II1 _L, _II2 _X)
  107. {
  108. for (; _F != _L && *_F == *_X; ++_F, ++_X)
  109. ;
  110. return (pair<_II1, _II2>(_F, _X));
  111. }
  112. // TEMPLATE FUNCTION mismatch WITH PRED
  113. template<class _II1, class _II2, class _Pr> inline
  114. pair<_II1, _II2> mismatch(_II1 _F, _II1 _L, _II2 _X, _Pr _P)
  115. {
  116. for (; _F != _L && _P(*_F, *_X); ++_F, ++_X)
  117. ;
  118. return (pair<_II1, _II2>(_F, _X));
  119. }
  120. // TEMPLATE FUNCTION swap
  121. template<class _Ty> inline
  122. void swap(_Ty& _X, _Ty& _Y)
  123. {
  124. _Ty _Tmp = _X;
  125. _X = _Y, _Y = _Tmp;
  126. }
  127. _STD_END
  128. #ifdef _MSC_VER
  129. #pragma pack(pop)
  130. #endif /* _MSC_VER */
  131. #endif /* _STLXUTIL_H_ */
  132. /*
  133. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  134. * Consult your license regarding permissions and restrictions.
  135. */
  136. /*
  137. * This file is derived from software bearing the following
  138. * restrictions:
  139. *
  140. * Copyright (c) 1994
  141. * Hewlett-Packard Company
  142. *
  143. * Permission to use, copy, modify, distribute and sell this
  144. * software and its documentation for any purpose is hereby
  145. * granted without fee, provided that the above copyright notice
  146. * appear in all copies and that both that copyright notice and
  147. * this permission notice appear in supporting documentation.
  148. * Hewlett-Packard Company makes no representations about the
  149. * suitability of this software for any purpose. It is provided
  150. * "as is" without express or implied warranty.
  151. */