⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utility

📁 C语言库函数的原型,有用的拿去
💻
字号:
// utility standard header
#pragma once
#ifndef _UTILITY_
#define _UTILITY_
#ifndef RC_INVOKED
#include <xstddef>
#include <iosfwd>

#include <type_traits>

 #pragma pack(push,_CRT_PACKING)
 #pragma warning(push,3)

 #pragma warning(disable: 4180 4512)

_STD_BEGIN
	namespace tr1 {
	// CLASS _Unrefwrap
template<class _Type>
	class reference_wrapper;

 #if _HAS_CPP0X
template<class _Type>
	struct _Unrefwrap
	{	// unwrap a reference_wrapper
	typedef typename decay<_Type>::type type;
	};

template<class _Type>
	struct _Unrefwrap<reference_wrapper<_Type> >
	{	// make a reference from a reference_wrapper
	typedef _Type& type;
	};

template<class _Type>
	struct _Unrefwrap<const reference_wrapper<_Type> >
	{	// make a reference from a const reference_wrapper
	typedef _Type& type;
	};

template<class _Type>
	struct _Unrefwrap<volatile reference_wrapper<_Type> >
	{	// make a reference from a volatile reference_wrapper
	typedef _Type& type;
	};

template<class _Type>
	struct _Unrefwrap<const volatile reference_wrapper<_Type> >
	{	// make a reference from a const volatile reference_wrapper
	typedef _Type& type;
	};

 #else /* _HAS_CPP0X */
template<class _Type>
	struct _Unrefwrap
	{	// unwrap a reference_wrapper
	typedef _Type type;
	};
 #endif /* _HAS_CPP0X */
	}	// namespace tr1
using tr1::_Unrefwrap;

	// TEMPLATE CLASS identity
template<class _Ty>
	struct identity
	{	// map _Ty to type unchanged
	typedef _Ty type;

	const _Ty& operator()(const _Ty& _Left) const
		{	// apply identity operator to operand
		return (_Left);
		}
	};

	// TEMPLATE FUNCTION forward
template<class _Ty> inline
	_Ty&& forward(typename identity<_Ty>::type& _Arg)
	{	// forward _Arg, given explicitly specified type parameter
	return ((_Ty&&)_Arg);
	}

	// TEMPLATE FUNCTION move
template<class _Ty> inline
	typename tr1::_Remove_reference<_Ty>::_Type&&
		move(_Ty&& _Arg)
	{	// forward _Arg as movable
	return ((typename tr1::_Remove_reference<_Ty>::_Type&&)_Arg);
	}

	// TEMPLATE FUNCTION _Move
template<class _Ty> inline
	typename tr1::_Remove_reference<_Ty>::_Type&&
		_Move(_Ty&& _Arg)
	{	// forward _Arg as movable
	return ((typename tr1::_Remove_reference<_Ty>::_Type&&)_Arg);
	}

		// TEMPLATE FUNCTION swap (from <algorithm>)
template<class _Ty> inline
	void swap(_Ty& _Left, _Ty& _Right)
	{	// exchange values stored at _Left and _Right
	_Ty _Tmp = _Move(_Left);
	_Left = _Move(_Right);
	_Right = _Move(_Tmp);
	}

		// TEMPLATE FUNCTION _Swap_adl
template<class _Ty> inline
	void _Swap_adl(_Ty& _Left, _Ty& _Right)
	{	// exchange values stored at _Left and _Right, using ADL
	swap(_Left, _Right);
	}

		// TEMPLATE STRUCT pair

template<class _Ty1,
	class _Ty2>
	struct _Pair_base
	{	// store a pair of values
	typedef _Pair_base<_Ty1, _Ty2> _Myt;
	typedef _Ty1 first_type;
	typedef _Ty2 second_type;

	_Pair_base()
		: first(_Ty1()), second(_Ty2())
		{	// construct from defaults
		}

	_Pair_base(const _Pair_base<_Ty1, _Ty2>& _Right)
		: first(_Right.first), second(_Right.second)
		{	// construct by copying _Pair_base
		}

	_Pair_base(const _Ty1& _Val1, const _Ty2& _Val2)
		: first(_Val1), second(_Val2)
		{	// construct from specified values
		}

	typedef typename tr1::remove_reference<_Ty1>::type _Ty1x;
	typedef typename tr1::remove_reference<_Ty2>::type _Ty2x;

	_Pair_base(_Ty1x&& _Val1, _Ty2x&& _Val2)
		: first(_STD move(_Val1)),
			second(_STD move(_Val2))
		{	// construct from specified values
		}

	_Pair_base(const _Ty1x& _Val1, _Ty2x&& _Val2)
		: first(_Val1), second(_STD move(_Val2))
		{	// construct from specified values
		}

	_Pair_base(_Ty1x&& _Val1, const _Ty2x& _Val2)
		: first(_STD move(_Val1)), second(_Val2)
		{	// construct from specified values
		}

	template<class _Other1,
		class _Other2>
		_Pair_base(_Other1&& _Val1, _Other2&& _Val2)
		: first(_STD forward<_Other1>(_Val1)),
			second(_STD forward<_Other2>(_Val2))
		{	// construct from moved values
		}

	_Ty1 first;	// the first stored value
	_Ty2 second;	// the second stored value
	};

template<class _Ty1,
	class _Ty2>
	struct pair
		: public _Pair_base<_Ty1, _Ty2>
	{	// store a pair of values
	typedef _Pair_base<_Ty1, _Ty2> _Mybase;

	typedef pair<_Ty1, _Ty2> _Myt;
	typedef _Ty1 first_type;
	typedef _Ty2 second_type;

	pair()
		: _Mybase()
		{	// construct from defaults
		}

	pair(const _Ty1& _Val1, const _Ty2& _Val2)
		: _Mybase(_Val1, _Val2)
		{	// construct from specified values
		}

	template<class _Other1,
		class _Other2>
		pair(pair<_Other1, _Other2>& _Right)
		: _Mybase(_Right.first, _Right.second)
		{	// construct from compatible pair
		}

	template<class _Other1,
		class _Other2>
		pair(const pair<_Other1, _Other2>& _Right)
		: _Mybase(_Right.first, _Right.second)
		{	// construct from compatible pair
		}

	void swap(_Myt& _Right)
		{	// exchange contents with _Right
		if (this != &_Right)
			{	// different, worth swapping
			_Swap_adl(this->first, _Right.first);
			_Swap_adl(this->second, _Right.second);
			}
		}

	_Myt& operator=(const _Myt& _Right)
		{	// assign from copied pair
		this->first = _Right.first;
		this->second = _Right.second;
		return (*this);
		}

	typedef typename tr1::remove_reference<_Ty1>::type _Ty1x;
	typedef typename tr1::remove_reference<_Ty2>::type _Ty2x;

	pair(_Ty1x&& _Val1, _Ty2x&& _Val2)
		: _Mybase(_STD move(_Val1),
			_STD move(_Val2))
		{	// construct from specified values
		}

	pair(const _Ty1x& _Val1, _Ty2x&& _Val2)
		: _Mybase(_Val1,
			_STD move(_Val2))
		{	// construct from specified values
		}

	pair(_Ty1x&& _Val1, const _Ty2x& _Val2)
		: _Mybase(_STD move(_Val1),
			_Val2)
		{	// construct from specified values
		}

	template<class _Other1,
		class _Other2>
		pair(_Other1&& _Val1, _Other2&& _Val2)
		: _Mybase(_STD forward<_Other1>(_Val1),
			_STD forward<_Other2>(_Val2))
		{	// construct from moved values
		}

	template<class _Other1,
		class _Other2>
		pair(pair<_Other1, _Other2>&& _Right)
		: _Mybase(_STD forward<_Other1>(_Right.first),
			_STD forward<_Other2>(_Right.second))
		{	// construct from moved compatible pair
		}

	pair& operator=(pair<_Ty1, _Ty2>&& _Right)
		{	// assign from moved pair
		this->first = _STD move(_Right.first);
		this->second = _STD move(_Right.second);
		return (*this);
		}

	void swap(_Myt&& _Right)
		{	// exchange contents with _Right
		if (this != &_Right)
			{	// different, worth swapping
			this->first = _STD move(_Right.first);
			this->second = _STD move(_Right.second);
			}
		}
	};

		// pair TEMPLATE FUNCTIONS

template<class _Ty1,
	class _Ty2> inline
	void swap(pair<_Ty1, _Ty2>& _Left, pair<_Ty1, _Ty2>& _Right)
	{	// swap _Left and _Right pairs
	_Left.swap(_Right);
	}

template<class _Ty1,
	class _Ty2> inline
	void swap(pair<_Ty1, _Ty2>& _Left, pair<_Ty1, _Ty2>&& _Right)
	{	// swap _Left and _Right pairs
	typedef pair<_Ty1, _Ty2> _Myt;
	_Left.swap(_STD forward<_Myt>(_Right));
	}

template<class _Ty1,
	class _Ty2> inline
	void swap(pair<_Ty1, _Ty2>&& _Left, pair<_Ty1, _Ty2>& _Right)
	{	// swap _Left and _Right pairs
	typedef pair<_Ty1, _Ty2> _Myt;
	_Right.swap(_STD forward<_Myt>(_Left));
	}

template<class _Ty1,
	class _Ty2> inline
	bool operator==(const pair<_Ty1, _Ty2>& _Left,
		const pair<_Ty1, _Ty2>& _Right)
	{	// test for pair equality
	return (_Left.first == _Right.first && _Left.second == _Right.second);
	}

template<class _Ty1,
	class _Ty2> inline
	bool operator!=(const pair<_Ty1, _Ty2>& _Left,
		const pair<_Ty1, _Ty2>& _Right)
	{	// test for pair inequality
	return (!(_Left == _Right));
	}

template<class _Ty1,
	class _Ty2> inline
	bool operator<(const pair<_Ty1, _Ty2>& _Left,
		const pair<_Ty1, _Ty2>& _Right)
	{	// test if _Left < _Right for pairs
	return (_Left.first < _Right.first ||
		!(_Right.first < _Left.first) && _Left.second < _Right.second);
	}

template<class _Ty1,
	class _Ty2> inline
	bool operator>(const pair<_Ty1, _Ty2>& _Left,
		const pair<_Ty1, _Ty2>& _Right)
	{	// test if _Left > _Right for pairs
	return (_Right < _Left);
	}

template<class _Ty1,
	class _Ty2> inline
	bool operator<=(const pair<_Ty1, _Ty2>& _Left,
		const pair<_Ty1, _Ty2>& _Right)
	{	// test if _Left <= _Right for pairs
	return (!(_Right < _Left));
	}

template<class _Ty1,
	class _Ty2> inline
	bool operator>=(const pair<_Ty1, _Ty2>& _Left,
		const pair<_Ty1, _Ty2>& _Right)
	{	// test if _Left >= _Right for pairs
	return (!(_Left < _Right));
	}

	// TEMPLATE FUNCTION make_pair

template<class _Ty1,
	class _Ty2> inline
	pair<typename _Unrefwrap<_Ty1>::type,
		typename _Unrefwrap<_Ty2>::type>
		make_pair(_Ty1&& _Val1, _Ty2&& _Val2)
	{	// return pair composed from arguments
	typedef pair<typename _Unrefwrap<_Ty1>::type,
		typename _Unrefwrap<_Ty2>::type> _Mypair;
	return (_Mypair(_STD forward<_Ty1>(_Val1),
		_STD forward<_Ty2>(_Val2)));
	}

template<class _Ty1,
	class _Ty2> inline
	pair<typename _Unrefwrap<_Ty1>::type,
		typename _Unrefwrap<_Ty2>::type>
		make_pair(const _Ty1& _Val1, _Ty2&& _Val2)
	{	// return pair composed from arguments
	typedef pair<typename _Unrefwrap<_Ty1>::type,
		typename _Unrefwrap<_Ty2>::type> _Mypair;
	return (_Mypair((typename _Unrefwrap<_Ty1>::type)_Val1,
		_STD forward<_Ty2>(_Val2)));
	}

template<class _Ty1,
	class _Ty2> inline
	pair<typename _Unrefwrap<_Ty1>::type,
		typename _Unrefwrap<_Ty2>::type>
		make_pair(_Ty1&& _Val1, const _Ty2& _Val2)
	{	// return pair composed from arguments
	typedef pair<typename _Unrefwrap<_Ty1>::type,
		typename _Unrefwrap<_Ty2>::type> _Mypair;
	return (_Mypair(_STD forward<_Ty1>(_Val1),
		(typename _Unrefwrap<_Ty2>::type)_Val2));
	}

template<class _Ty1,
	class _Ty2> inline
	pair<typename _Unrefwrap<_Ty1>::type,
		typename _Unrefwrap<_Ty2>::type>
		make_pair(const _Ty1& _Val1, const _Ty2& _Val2)
	{	// return pair composed from arguments
	typedef pair<typename _Unrefwrap<_Ty1>::type,
		typename _Unrefwrap<_Ty2>::type> _Mypair;
	return (_Mypair((typename _Unrefwrap<_Ty1>::type)_Val1,
		(typename _Unrefwrap<_Ty2>::type)_Val2));
	}

 #if _HAS_CPP0X
template<class _InIt> inline
	_InIt begin(const pair<_InIt, _InIt>& _Pair)
	{	// return first element of pair
	return (_Pair.first);
	}

template<class _InIt> inline
	_InIt end(const pair<_InIt, _InIt>& _Pair)
	{	// return second element of pair
	return (_Pair.second);
	}
 #endif /* _HAS_CPP0X */

		// TEMPLATE OPERATORS
	namespace rel_ops
		{	// nested namespace to hide relational operators from std
template<class _Ty> inline
	bool operator!=(const _Ty& _Left, const _Ty& _Right)
	{	// test for inequality, in terms of equality
	return (!(_Left == _Right));
	}

template<class _Ty> inline
	bool operator>(const _Ty& _Left, const _Ty& _Right)
	{	// test if _Left > _Right, in terms of operator<
	return (_Right < _Left);
	}

template<class _Ty> inline
	bool operator<=(const _Ty& _Left, const _Ty& _Right)
	{	// test if _Left <= _Right, in terms of operator<
	return (!(_Right < _Left));
	}

template<class _Ty> inline
	bool operator>=(const _Ty& _Left, const _Ty& _Right)
	{	// test if _Left >= _Right, in terms of operator<
	return (!(_Left < _Right));
	}
		}
_STD_END

 #if _HAS_TR1
_STD_BEGIN
	namespace tr1 {	// TR1 additions
	// TUPLE INTERFACE TO _STD tr1::pair
template<class _Tuple>
	struct tuple_size;
template<size_t _Idx,
	class _Tuple>
	struct tuple_element;
template<class _Ty1,
	class _Ty2>
	struct tuple_size<_STD pair<_Ty1, _Ty2> >
	{	// struct to determine number of elements in pair
	static const int value = 2;
	};

template<int _Idx,
	class _Ty>
	struct _Pair_data;
template<class _Ty1,
	class _Ty2>
	struct _Pair_data<0, _STD pair<_Ty1, _Ty2> >
	{	// struct to pick out argument type and value at index 0
	typedef _Ty1& _Type;
	typedef const _Ty1& _CType;

	static _Type _Val(_STD pair<_Ty1, _Ty2>& _Pr)
		{	// return value
		return (_Pr.first);
		}

	static _CType _Val(const _STD pair<_Ty1, _Ty2>& _Pr)
		{	// return value
		return (_Pr.first);
		}
	};

template<class _Ty1,
	class _Ty2>
	struct _Pair_data<1, _STD pair<_Ty1, _Ty2> >
	{	// struct to pick out argument type and value at index 1
	typedef _Ty2& _Type;
	typedef const _Ty2& _CType;

	static _Type _Val(_STD pair<_Ty1, _Ty2>& _Pr)
		{	// return value
		return (_Pr.second);
		}

	static _CType _Val(const _STD pair<_Ty1, _Ty2>& _Pr)
		{	// return value
		return (_Pr.second);
		}
	};

template<class _Ty1,
	class _Ty2>
	struct tuple_element<0, _STD pair<_Ty1, _Ty2> >
	{	// struct to determine type of element 0 in pair
	typedef _Ty1 type;
	};

template<class _Ty1,
	class _Ty2>
	struct tuple_element<1, _STD pair<_Ty1, _Ty2> >
	{	// struct to determine type of element 1 in pair
	typedef _Ty2 type;
	};

template<int _Idx,
	class _Ty1,
	class _Ty2>
	typename _Pair_data<_Idx, _STD pair<_Ty1, _Ty2> >::_Type
		get(_STD pair<_Ty1, _Ty2>& _Pr)
	{	// return element at _Idx in pair _Pr
	return (_Pair_data<_Idx, _STD pair<_Ty1, _Ty2> >::_Val(_Pr));
	}

template<int _Idx,
	class _Ty1,
	class _Ty2>
	typename _Pair_data<_Idx, _STD pair<_Ty1, _Ty2> >::_CType
		get(const _STD pair<_Ty1, _Ty2>& _Pr)
	{	// return element at _Idx in pair _Pr
	return (_Pair_data<_Idx, _STD pair<_Ty1, _Ty2> >::_Val(_Pr));
	}
	}	// namespace tr1
_STD_END
 #endif /* _HAS_TR1 */

 #if _HAS_TR1_IMPORTS
_STD_BEGIN
using tr1::get;
using tr1::tuple_element;
using tr1::tuple_size;
_STD_END
 #endif /* _HAS_TR1_IMPORTS */

 #pragma warning(pop)
 #pragma pack(pop)

#endif /* RC_INVOKED */
#endif /* _UTILITY_ */

/*
 * 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.
 */

/*
 * Copyright (c) 1992-2009 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V5.20:0009 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -