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.

124 lines
3.9 KiB

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