146 lines
4.2 KiB
Plaintext
146 lines
4.2 KiB
Plaintext
|
// xutility internal header
|
||
|
#ifndef _XUTILITY_
|
||
|
#define _XUTILITY_
|
||
|
#include <use_ansi.h>
|
||
|
#include <utility>
|
||
|
|
||
|
#ifdef _MSC_VER
|
||
|
/*
|
||
|
* Currently, all MS C compilers for Win32 platforms default to 8 byte
|
||
|
* alignment.
|
||
|
*/
|
||
|
#pragma pack(push,8)
|
||
|
#endif /* _MSC_VER */
|
||
|
|
||
|
// TEMPLATE FUNCTION copy
|
||
|
template<class _II, class _OI> inline
|
||
|
_OI copy(_II _F, _II _L, _OI _X)
|
||
|
{for (; _F != _L; ++_X, ++_F)
|
||
|
*_X = *_F;
|
||
|
return (_X); }
|
||
|
// TEMPLATE FUNCTION copy_backward
|
||
|
template<class _BI1, class _BI2> inline
|
||
|
_BI2 copy_backward(_BI1 _F, _BI1 _L, _BI2 _X)
|
||
|
{while (_F != _L)
|
||
|
*--_X = *--_L;
|
||
|
return (_X); }
|
||
|
// TEMPLATE FUNCTION equal
|
||
|
template<class _II1, class _II2> inline
|
||
|
bool equal(_II1 _F, _II1 _L, _II2 _X)
|
||
|
{return (mismatch(_F, _L, _X).first == _L); }
|
||
|
// TEMPLATE FUNCTION equal WITH PRED
|
||
|
template<class _II1, class _II2, class _Pr> inline
|
||
|
bool equal(_II1 _F, _II1 _L, _II2 _X, _Pr _P)
|
||
|
{return (mismatch(_F, _L, _X, _P).first == _L); }
|
||
|
// TEMPLATE FUNCTION fill
|
||
|
template<class _FI, class _TYPE> inline
|
||
|
void fill(_FI _F, _FI _L, const _TYPE& _X)
|
||
|
{for (; _F != _L; ++_F)
|
||
|
*_F = _X; }
|
||
|
// TEMPLATE FUNCTION fill_n
|
||
|
template<class _OI, class _Sz, class _TYPE> inline
|
||
|
void fill_n(_OI _F, _Sz _N, const _TYPE& _X)
|
||
|
{for (; 0 < _N; --_N, ++_F)
|
||
|
*_F = _X; }
|
||
|
// TEMPLATE FUNCTION lexicographical_compare
|
||
|
template<class _II1, class _II2> inline
|
||
|
bool lexicographical_compare(_II1 _F1, _II1 _L1,
|
||
|
_II2 _F2, _II2 _L2)
|
||
|
{for (; _F1 != _L1 && _F2 != _L2; ++_F1, ++_F2)
|
||
|
if (*_F1 < *_F2)
|
||
|
return (true);
|
||
|
else if (*_F2 < *_F1)
|
||
|
return (false);
|
||
|
return (_F1 == _L1 && _F2 != _L2); }
|
||
|
// TEMPLATE FUNCTION lexicographical_compare WITH PRED
|
||
|
template<class _II1, class _II2, class _Pr> inline
|
||
|
bool lexicographical_compare(_II1 _F1, _II1 _L1,
|
||
|
_II2 _F2, _II2 _L2, _Pr _P)
|
||
|
{for (; _F1 != _L1 && _F2 != _L2; ++_F1, ++_F2)
|
||
|
if (_P(*_F1, *_F2))
|
||
|
return (true);
|
||
|
else if (_P(*_F2, *_F1))
|
||
|
return (false);
|
||
|
return (_F1 == _L1 && _F2 != _L2); }
|
||
|
|
||
|
|
||
|
// TEMPLATE FUNCTION _cpp_max
|
||
|
|
||
|
// NOTE: standard min & max templates have been temporarily renamed
|
||
|
// _cpp_min & _cpp_max to prevent collision with min/max macros in windef.h
|
||
|
|
||
|
template<class _TYPE> inline
|
||
|
const _TYPE& _cpp_max(const _TYPE& _X, const _TYPE& _Y)
|
||
|
{if (_X < _Y)
|
||
|
return (_Y);
|
||
|
else
|
||
|
return (_X); }
|
||
|
// TEMPLATE FUNCTION _cpp_max WITH PRED
|
||
|
template<class _TYPE, class _Pr> inline
|
||
|
const _TYPE& _cpp_max(const _TYPE& _X, const _TYPE& _Y, _Pr _P)
|
||
|
{if (_P(_X, _Y))
|
||
|
return (_Y);
|
||
|
else
|
||
|
return (_X); }
|
||
|
// TEMPLATE FUNCTION _cpp_min
|
||
|
template<class _TYPE> inline
|
||
|
const _TYPE& _cpp_min(const _TYPE& _X, const _TYPE& _Y)
|
||
|
{if (_X < _Y)
|
||
|
return (_X);
|
||
|
else
|
||
|
return (_Y); }
|
||
|
// TEMPLATE FUNCTION _cpp_min WITH PRED
|
||
|
template<class _TYPE, class _Pr> inline
|
||
|
const _TYPE& _cpp_min(const _TYPE& _X, const _TYPE& _Y, _Pr _P)
|
||
|
{if (_P(_Y, _X))
|
||
|
return (_Y);
|
||
|
else
|
||
|
return (_X); }
|
||
|
|
||
|
|
||
|
// TEMPLATE FUNCTION mismatch
|
||
|
template<class _II1, class _II2> inline
|
||
|
pair<_II1, _II2> mismatch(_II1 _F, _II1 _L, _II2 _X)
|
||
|
{for (; _F != _L && *_F == *_X; ++_F, ++_X)
|
||
|
;
|
||
|
return (pair<_II1, _II2>(_F, _X)); }
|
||
|
// TEMPLATE FUNCTION mismatch WITH PRED
|
||
|
template<class _II1, class _II2, class _Pr> inline
|
||
|
pair<_II1, _II2> mismatch(_II1 _F, _II1 _L, _II2 _X, _Pr _P)
|
||
|
{for (; _F != _L && _P(*_F, *_X); ++_F, ++_X)
|
||
|
;
|
||
|
return (pair<_II1, _II2>(_F, _X)); }
|
||
|
// TEMPLATE FUNCTION swap
|
||
|
template<class _TYPE> inline
|
||
|
void swap(_TYPE& _X, _TYPE& _Y)
|
||
|
{_TYPE _Tmp = _X;
|
||
|
_X = _Y, _Y = _Tmp; }
|
||
|
|
||
|
#ifdef _MSC_VER
|
||
|
#pragma pack(pop)
|
||
|
#endif /* _MSC_VER */
|
||
|
|
||
|
#endif /* _XUTILITY_ */
|
||
|
|
||
|
/*
|
||
|
* Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
|
||
|
* Consult your license regarding permissions and restrictions.
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
* This file is derived from software bearing the following
|
||
|
* restrictions:
|
||
|
*
|
||
|
* Copyright (c) 1994
|
||
|
* Hewlett-Packard Company
|
||
|
*
|
||
|
* Permission to use, copy, modify, distribute and sell this
|
||
|
* software and its documentation for any purpose is hereby
|
||
|
* granted without fee, provided that the above copyright notice
|
||
|
* appear in all copies and that both that copyright notice and
|
||
|
* this permission notice appear in supporting documentation.
|
||
|
* Hewlett-Packard Company makes no representations about the
|
||
|
* suitability of this software for any purpose. It is provided
|
||
|
* "as is" without express or implied warranty.
|
||
|
*/
|