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

📄 memory

📁 C语言库函数的原型,有用的拿去
💻
📖 第 1 页 / 共 5 页
字号:
	void _Uninit_fill_n(_FwdIt _First, _Diff _Count, const _Tval& _Val,
		_Nonscalar_ptr_iterator_tag)
	{	// copy _Count *_Val to raw _First, arbitrary type
 #if _ITERATOR_DEBUG_LEVEL == 2
//	if (_Count < 0)
//		_DEBUG_ERROR("negative count in uninitialized fill");
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */

	_FwdIt _Next = _First;

	_TRY_BEGIN
	for (; 0 < _Count; --_Count, ++_First)
		_Construct(&*_First, _Val);
	_CATCH_ALL
	for (; _Next != _First; ++_Next)
		_Destroy(&*_Next);
	_RERAISE;
	_CATCH_END
	}

template<class _Ty,
	class _Diff,
	class _Tval> inline
	void _Uninit_fill_n(_Ty *_First, _Diff _Count, const _Tval& _Val,
		_Scalar_ptr_iterator_tag)
	{	// copy _Count *_Val to raw _First, scalar type
	_STD _Fill_n(_First, _Count, _Val);
	}

template<class _FwdIt,
	class _Diff,
	class _Tval> inline
	void uninitialized_fill_n(_FwdIt _First, _Diff _Count, const _Tval& _Val)
	{	// copy _Count *_Val to raw _First
	_Uninit_fill_n(_First, _Count, _Val, _Ptr_cat(_First, _First));
	}

		// TEMPLATE FUNCTION _Uninitialized_fill_n WITH ALLOCATOR
template<class _FwdIt,
	class _Diff,
	class _Tval,
	class _Alloc,
	class _Valty> inline
	void _Uninit_fill_n(_FwdIt _First, _Diff _Count,
		const _Tval *_Pval, _Alloc& _Al,
			_Valty *, _Nonscalar_ptr_iterator_tag)
	{	// copy _Count * *_Pval to raw _First, using _Al, arbitrary type
 #if _ITERATOR_DEBUG_LEVEL == 2
//	if (_Count < 0)
//		_DEBUG_ERROR("negative count in uninitialized fill");
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */

	_FwdIt _Next = _First;

	_TRY_BEGIN
	for (; 0 < _Count; --_Count, ++_First)
		_Cons_val(_Al, _First, *_Pval);
	_CATCH_ALL
	for (; _Next != _First; ++_Next)
		_Dest_val(_Al, _Next);
	_RERAISE;
	_CATCH_END
	}

template<class _FwdIt,
	class _Diff,
	class _Tval,
	class _Alloc,
	class _Valty> inline
	void _Uninit_fill_n(_FwdIt _First, _Diff _Count,
		const _Tval *_Pval, _Alloc& _Al,
			_Valty *, _Scalar_ptr_iterator_tag)
	{	// copy _Count * *_Pval to raw _First, using _Al, arbitrary type
	_Uninit_fill_n(_First, _Count,
		_Pval, _Al, (_Valty *)0, _Nonscalar_ptr_iterator_tag());
	}

template<class _Ty,
	class _Diff,
	class _Tval,
	class _Valty> inline
	void _Uninit_fill_n(_Ty *_First, _Diff _Count,
		const _Tval *_Pval, allocator<_Ty>&,
			_Valty *, _Scalar_ptr_iterator_tag)
	{	// copy _Count * *_Pval to raw _First, using _Al, scalar type
	_Fill_n(_First, _Count, *_Pval);
	}

template<class _FwdIt,
	class _Diff,
	class _Tval,
	class _Alloc> inline
	void _Uninitialized_fill_n(_FwdIt _First, _Diff _Count,
		const _Tval *_Pval, _Alloc& _Al)
	{	// copy _Count * *_Pval to raw _First, using _Al
	_Uninit_fill_n(_First, _Count, _Pval, _Al,
		_Val_type(_First), _Ptr_cat(_First, _First));
	}

		// TEMPLATE FUNCTION _Uninitialized_default_fill_n WITH ALLOCATOR
template<class _FwdIt,
	class _Diff,
	class _Tval,
	class _Alloc,
	class _Valty> inline
	void _Uninit_def_fill_n(_FwdIt _First, _Diff _Count,
		const _Tval *, _Alloc& _Al,
			_Valty *, _Nonscalar_ptr_iterator_tag)
	{	// copy _Count * _Valty() to raw _First, using _Al, arbitrary type
 #if _ITERATOR_DEBUG_LEVEL == 2
//	if (_Count < 0)
//		_DEBUG_ERROR("negative count in uninitialized fill");
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */

	_FwdIt _Next = _First;

	_TRY_BEGIN
	for (; 0 < _Count; --_Count, ++_First)

		_Cons_val(_Al, _First, _Valty());

	_CATCH_ALL
	for (; _Next != _First; ++_Next)
		_Dest_val(_Al, _Next);
	_RERAISE;
	_CATCH_END
	}

template<class _FwdIt,
	class _Diff,
	class _Tval,
	class _Alloc,
	class _Valty> inline
	void _Uninit_def_fill_n(_FwdIt _First, _Diff _Count,
		const _Tval *_Pval, _Alloc& _Al,
			_Valty *, _Scalar_ptr_iterator_tag)
	{	// copy _Count * _Valty() to raw _First, using _Al, arbitrary type
	_Uninit_def_fill_n(_First, _Count,
		_Pval, _Al, (_Valty *)0, _Nonscalar_ptr_iterator_tag());
	}

template<class _Ty,
	class _Diff,
	class _Tval,
	class _Valty> inline
	void _Uninit_def_fill_n(_Ty *_First, _Diff _Count,
		const _Tval *, allocator<_Ty>&,
			_Valty *, _Scalar_ptr_iterator_tag)
	{	// copy _Count * _Valty() to raw _First, using _Al, scalar type
	_Fill_n(_First, _Count, (_Valty)0);
	}

template<class _FwdIt,
	class _Diff,
	class _Tval,
	class _Alloc> inline
	void _Uninitialized_default_fill_n(_FwdIt _First, _Diff _Count,
		const _Tval *_Pval, _Alloc& _Al)
	{	// copy _Count * _Val_type(_First)() to raw _First, using _Al
	_Uninit_def_fill_n(_First, _Count, _Pval, _Al,
		_Val_type(_First), _Ptr_cat(_First, _First));
	}

		// TEMPLATE CLASS raw_storage_iterator
template<class _FwdIt,
	class _Ty>
	class raw_storage_iterator
		: public _Outit
	{	// wrap stores to raw buffer as output iterator
public:
	typedef _FwdIt iterator_type;	// retained
	typedef _FwdIt iter_type;	// retained
	typedef _Ty element_type;	// retained

	explicit raw_storage_iterator(_FwdIt _First)
		: _Next(_First)
		{	// construct with iterator
		}

	raw_storage_iterator<_FwdIt, _Ty>& operator*()
		{	// pretend to return designated value
		return (*this);
		}

	raw_storage_iterator<_FwdIt, _Ty>& operator=(const _Ty& _Val)
		{	// construct value designated by stored iterator
		_Construct(&*_Next, _Val);
		return (*this);
		}

	raw_storage_iterator<_FwdIt, _Ty>& operator++()
		{	// preincrement
		++_Next;
		return (*this);
		}

	raw_storage_iterator<_FwdIt, _Ty> operator++(int)
		{	// postincrement
		raw_storage_iterator<_FwdIt, _Ty> _Ans = *this;
		++_Next;
		return (_Ans);
		}

private:
	_FwdIt _Next;	// the stored iterator
	};

		// TEMPLATE CLASS _Temp_iterator
template<class _Ty>
	class _Temp_iterator
		: public _Outit
	{	// wrap stores to temporary buffer as output iterator
public:
	typedef _Ty _FARQ *_Pty;

	_Temp_iterator(_PDFT _Count = 0)
		{	// construct from desired temporary buffer size
		_Buf._Begin = 0;
		_Buf._Current = 0;
		_Buf._Hiwater = 0;
		_Buf._Size = _Count;	// memorize size for lazy allocation
		_Pbuf = &_Buf;
		}

	_Temp_iterator(const _Temp_iterator<_Ty>& _Right)
		{	// construct from _Right (share active buffer)
		_Buf._Begin = 0;	// clear stored buffer, for safe destruction
		_Buf._Current = 0;
		_Buf._Hiwater = 0;
		_Buf._Size = 0;
		*this = _Right;
		}

	~_Temp_iterator()
		{	// destroy the object
		if (_Buf._Begin != 0)
			{	// destroy any constructed elements in buffer
			for (_Pty _Next = _Buf._Begin;
				_Next != _Buf._Hiwater; ++_Next)
				_Destroy(&*_Next);
			_STD return_temporary_buffer(_Buf._Begin);
			}
		}

	_Temp_iterator<_Ty>& operator=(const _Temp_iterator<_Ty>& _Right)
		{	// assign _Right (share active buffer)
		_Pbuf = _Right._Pbuf;
		return (*this);
		}

	_Temp_iterator<_Ty>& operator=(const _Ty& _Val)
		{	// assign or construct value into active buffer, and increment
		if (_Pbuf->_Current < _Pbuf->_Hiwater)
			*_Pbuf->_Current++ = _Val;	// below high water mark, assign
		else
			{	// above high water mark, construct
			_Pty _Ptr = &*_Pbuf->_Current;
			_Construct(_Ptr, _Val);
			_Pbuf->_Hiwater = ++_Pbuf->_Current;
			}
		return (*this);
		}

	_Temp_iterator<_Ty>& operator=(_Ty&& _Val)
		{	// move or construct value into active buffer, and increment
		if (_Pbuf->_Current < _Pbuf->_Hiwater)
			*_Pbuf->_Current++ =
				_STD forward<_Ty>(_Val);	// below high water mark, move
		else
			{	// above high water mark, construct
			_Pty _Ptr = &*_Pbuf->_Current;
			_Construct(_Ptr, _STD forward<_Ty>(_Val));
			_Pbuf->_Hiwater = ++_Pbuf->_Current;
			}
		return (*this);
		}

	_Temp_iterator<_Ty>& operator*()
		{	// pretend to return designated value
		return (*this);
		}

	_Temp_iterator<_Ty>& operator++()
		{	// pretend to preincrement
		return (*this);
		}

	_Temp_iterator<_Ty>& operator++(int)
		{	// pretend to postincrement
		return (*this);
		}

	_Temp_iterator<_Ty>& _Init()
		{	// set pointer at beginning of buffer
		_Pbuf->_Current = _Pbuf->_Begin;
		return (*this);
		}

	_Pty _First() const
		{	// return pointer to beginning of buffer
		return (_Pbuf->_Begin);
		}

	_Pty _Last() const
		{	// return pointer past end of buffer contents
		return (_Pbuf->_Current);
		}

	_PDFT _Maxlen()
		{	// return size of buffer
		if (_Pbuf->_Begin == 0 && 0 < _Pbuf->_Size)
			{	// allocate buffer on first size query
			pair<_Pty, _PDFT> _Pair =

				_STD get_temporary_buffer<_Ty>(_Pbuf->_Size);

			_Pbuf->_Begin = _Pair.first;
			_Pbuf->_Current = _Pair.first;
			_Pbuf->_Hiwater = _Pair.first;
			_Pbuf->_Size = _Pair.second;
			}
		return (_Pbuf->_Size);
		}

private:
	struct _Bufpar
		{	// control information for a temporary buffer
		_Pty _Begin;	// pointer to beginning of buffer
		_Pty _Current;	// pointer to next available element
		_Pty _Hiwater;	// pointer to first unconstructed element
		_PDFT _Size;	// length of buffer
		};
	_Bufpar _Buf;	// buffer control stored in iterator
	_Bufpar *_Pbuf;	// pointer to active buffer control
	};

		// TEMPLATE CLASS auto_ptr
template<class _Ty>
	class auto_ptr;

template<class _Ty>
	struct auto_ptr_ref
		{	// proxy reference for auto_ptr copying
	explicit auto_ptr_ref(_Ty *_Right)
		: _Ref(_Right)
		{	// construct from generic pointer to auto_ptr ptr
		}

	_Ty *_Ref;	// generic pointer to auto_ptr ptr
	};

template<class _Ty>
	class auto_ptr
		{	// wrap an object pointer to ensure destruction
public:
	typedef auto_ptr<_Ty> _Myt;
	typedef _Ty element_type;

	explicit auto_ptr(_Ty *_Ptr = 0) _THROW0()
		: _Myptr(_Ptr)
		{	// construct from object pointer
		}

	auto_ptr(_Myt& _Right) _THROW0()
		: _Myptr(_Right.release())
		{	// construct by assuming pointer from _Right auto_ptr
		}

	auto_ptr(auto_ptr_ref<_Ty> _Right) _THROW0()
		{	// construct by assuming pointer from _Right auto_ptr_ref
		_Ty *_Ptr = _Right._Ref;
		_Right._Ref = 0;	// release old
		_Myptr = _Ptr;	// reset this
		}

	template<class _Other>
		operator auto_ptr<_Other>() _THROW0()
		{	// convert to compatible auto_ptr
		return (auto_ptr<_Other>(*this));
		}

	template<class _Other>
		operator auto_ptr_ref<_Other>() _THROW0()
		{	// convert to compatible auto_ptr_ref
		_Other *_Cvtptr = _Myptr;	// test implicit conversion
		auto_ptr_ref<_Other> _Ans(_Cvtptr);
		_Myptr = 0;	// pass ownership to auto_ptr_ref
		return (_Ans);
		}

	template<class _Other>
		_Myt& operator=(auto_ptr<_Other>& _Right) _THROW0()
		{	// assign compatible _Right (assume pointer)
		reset(_Right.release());
		return (*this);
		}

	template<class _Other>
		auto_ptr(auto_ptr<_Other>& _Right) _THROW0()
		: _Myptr(_Right.release())
		{	// construct by assuming pointer from _Right
		}

	_Myt& operator=(_Myt& _Right) _THROW0()
		{	// assign compatible _Right (assume pointer)
		reset(_Right.release());
		return (*this);
		}

	_Myt& operator=(auto_ptr_ref<_Ty> _Right) _THROW0()
		{	// assign compatible _Right._Ref (assume pointer)
		_Ty *_Ptr = _Right._Ref;
		_Right._Ref = 0;	// release old
		reset(_Ptr);	// set new
		return (*this);
		}

	~auto_ptr()
		{	// destroy the object
		delete _Myptr;
		}

	_Ty& operator*() const _THROW0()
		{	// return designated value
 #if _ITERATOR_DEBUG_LEVEL == 2
		if (_Myptr == 0)
			_DEBUG_ERROR("auto_ptr not dereferencable");
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */

		return (*get());
		}

	_Ty *operator->() const _THROW0()
		{	// return pointer to class object
 #if _ITERATOR_DEBUG_LEVEL == 2
		if (_Myptr == 0)
			_DEBUG_ERROR("auto_ptr not dereferencable");
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */

		return (get());
		}

	_Ty *get() const _THROW0()
		{	// return wrapped pointer
		return (_Myptr);
		}

	_Ty *release() _THROW0()
		{	// return wrapped pointer and give up ownership
		_Ty *_Tmp = _Myptr;
		_Myptr = 0;
		return (_Tmp);
		}

	void reset(_Ty *_Ptr = 0)
		{	// destroy designated object and store new pointer
		if (_Ptr != _Myptr)
			delete _Myptr;
		_Myptr = _Ptr;
		}

private:
	_Ty *_Myptr;	// the wrapped object pointer
	};
_STD_END

 #if _HAS_TR1
 #ifndef _XSTD2
  #define _XSTD2
 #endif /* _XSTD2 */

 #include <exception>
 #include <typeinfo>
 #include <type_traits>

 #include <intrin.h>

  #define _MT_INCR(mtx, x)	_InterlockedIncrement(&x)
  #define _MT_DECR(mtx, x)	_InterlockedDecrement(&x)
  #define _MT_CMPX(x, y, z)	_InterlockedCompareExchange(&x, y, z)

_STD_BEGIN
 #if _HAS_CPP0X
template<class _Ty>
	struct default_delete;

template<class _Ty,
	class _Dx = default_delete<_Ty> >
	class unique_ptr;
 #endif /* _HAS_CPP0X */

	namespace tr1 {	// TR1 additions
	// CLASS bad_weak_ptr
class bad_weak_ptr
	: public exception
	{	// exception type for invalid use of expired weak_ptr object
public:
	explicit bad_weak_ptr(const char * = 0)
		{	// construct with ignored message
		}

	virtual const char *__CLR_OR_THIS_CALL what() const throw()
		{	// return pointer to message string
		return ("tr1::bad_weak_ptr");
		}
	};

	// CLASS _Ref_count_base
class _Ref_count_base
	{	// common code for reference counting
private:

⌨️ 快捷键说明

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