home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / xutility < prev    next >
Text File  |  1998-06-16  |  4KB  |  130 lines

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