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

📄 vector

📁 pwlib源码库
💻
📖 第 1 页 / 共 2 页
字号:
			return (_Tmp); }		const_iterator& operator--()			{_Dec();			return (*this); }		const_iterator operator--(int)			{const_iterator _Tmp = *this;			_Dec();			return (_Tmp); }		const_iterator& operator+=(difference_type _N)			{_Off += _N;			_Ptr += _Off / _VBITS;			_Off %= _VBITS;			return (*this); }		const_iterator& operator-=(difference_type _N)			{return (*this += -_N); }		const_iterator operator+(difference_type _N) const			{const_iterator _Tmp = *this;			return (_Tmp += _N); }		const_iterator operator-(difference_type _N) const			{const_iterator _Tmp = *this;			return (_Tmp -= _N); }		difference_type operator-(const const_iterator _X) const			{return (_VBITS * (_Ptr - _X._Ptr)				+ (difference_type)_Off				- (difference_type)_X._Off); }		const_reference operator[](difference_type _N) const			{return (*(*this + _N)); }		bool operator==(const const_iterator& _X) const			{return (_Ptr == _X._Ptr && _Off == _X._Off); }		bool operator!=(const const_iterator& _X) const			{return (!(*this == _X)); }		bool operator<(const const_iterator& _X) const			{return (_Ptr < _X._Ptr				|| _Ptr == _X._Ptr && _Off < _X._Off); }		bool operator>(const const_iterator& _X) const			{return (_X < *this); }		bool operator<=(const const_iterator& _X) const			{return (!(_X < *this)); }		bool operator>=(const const_iterator& _X) const			{return (!(*this < _X)); }	protected:		void _Dec()			{if (_Off != 0)				--_Off;			else				_Off = _VBITS - 1, --_Ptr; }		void _Inc()			{if (_Off < _VBITS - 1)				++_Off;			else				_Off = 0, ++_Ptr; }		size_t _Off;		_Vbase *_Ptr;		};		// CLASS iterator	class iterator : public const_iterator {	public:		iterator()			: const_iterator() {}		iterator(size_t _O, _Vbase *_P)			: const_iterator(_O, _P) {}		reference operator*() const			{return (reference(_Off, _Ptr)); }		iterator& operator++()			{_Inc();			return (*this); }		iterator operator++(int)			{iterator _Tmp = *this;			_Inc();			return (_Tmp); }		iterator& operator--()			{_Dec();			return (*this); }		iterator operator--(int)			{iterator _Tmp = *this;			_Dec();			return (_Tmp); }		iterator& operator+=(difference_type _N)			{_Off += _N;			_Ptr += _Off / _VBITS;			_Off %= _VBITS;			return (*this); }		iterator& operator-=(difference_type _N)			{return (*this += -_N); }		iterator operator+(difference_type _N) const			{iterator _Tmp = *this;			return (_Tmp += _N); }		iterator operator-(difference_type _N) const			{iterator _Tmp = *this;			return (_Tmp -= _N); }		difference_type operator-(const iterator _X) const			{return (_VBITS * (_Ptr - _X._Ptr)				+ (difference_type)_Off				- (difference_type)_X._Off); }		reference operator[](difference_type _N) const			{return (*(*this + _N)); }		bool operator==(const iterator& _X) const			{return (_Ptr == _X._Ptr && _Off == _X._Off); }		bool operator!=(const iterator& _X) const			{return (!(*this == _X)); }		bool operator<(const iterator& _X) const			{return (_Ptr < _X._Ptr				|| _Ptr == _X._Ptr && _Off < _X._Off); }		bool operator>(const iterator& _X) const			{return (_X < *this); }		bool operator<=(const iterator& _X) const			{return (!(_X < *this)); }		bool operator>=(const iterator& _X) const			{return (!(*this < _X)); }		};	typedef reverse_iterator<const_iterator, value_type,		const_reference, const_reference *, difference_type>			const_reverse_iterator;	typedef reverse_iterator<iterator, value_type,		reference, reference *, difference_type>			reverse_iterator;	explicit vector(const _A& _Al = _A())		: _Size(0), _Vec(_Al) {}	explicit vector(size_type _N, const bool _V = false,		const _A& _Al = _A())		: _Vec(_Nw(_N), _V ? -1 : 0, _Al) {_Trim(_N); }	typedef const_iterator _It;	vector(_It _F, _It _L, const _A& _Al = _A())		: _Size(0), _Vec(_Al)		{insert(begin(), _F, _L); }	~vector()		{_Size = 0; }	void reserve(size_type _N)		{_Vec.reserve(_Nw(_N)); }	size_type capacity() const		{return (_Vec.capacity() * _VBITS); }	iterator begin()		{return (iterator(0, _Vec.begin())); }	const_iterator begin() const		{return (const_iterator(0, _Vec.begin())); }	iterator end()		{iterator _Tmp = begin();		if (0 < _Size)			_Tmp += _Size;		return (_Tmp); }	const_iterator end() const		{const_iterator _Tmp = begin();		if (0 < _Size)			_Tmp += _Size;		return (_Tmp); }	reverse_iterator rbegin()		{return (reverse_iterator(end())); }	const_reverse_iterator rbegin() const		{return (const_reverse_iterator(end())); }	reverse_iterator rend()		{return (reverse_iterator(begin())); }	const_reverse_iterator rend() const		{return (const_reverse_iterator(begin())); }	void resize(size_type _N, bool _X = false)		{if (size() < _N)			insert(end(), _N - size(), _X);		else if (_N < size())			erase(begin() + _N, end()); }	size_type size() const		{return (_Size); }	size_type max_size() const		{return (_Vec.max_size() * _VBITS); }	bool empty() const		{return (size() == 0); }	_A get_allocator() const		{return (_Vec.get_allocator()); }	const_reference at(size_type _P) const		{if (size() <= _P)			_Xran();		return (*(begin() + _P)); }	reference at(size_type _P)		{if (size() <= _P)			_Xran();		return (*(begin() + _P)); }	const_reference operator[](size_type _P) const		{return (*(begin() + _P)); }	reference operator[](size_type _P)		{return (*(begin() + _P)); }	reference front()		{return (*begin()); }	const_reference front() const		{return (*begin()); }	reference back()		{return (*(end() - 1)); }	const_reference back() const		{return (*(end() - 1)); }	void push_back(const bool _X)		{insert(end(), _X); }	void pop_back()		{erase(end() - 1); }	void assign(_It _F, _It _L)		{erase(begin(), end());		insert(begin(), _F, _L); }	void assign(size_type _N, const bool _X = false)		{erase(begin(), end());		insert(begin(), _N, _X); }	iterator insert(iterator _P, const bool _X = false)		{size_type _O = _P - begin();		insert(_P, 1, _X);		return (begin() + _O); }	void insert(iterator _P, size_type _M, const bool _X)		{if (0 < _M)			{if (capacity() - size() < _M)				{size_type _O = _P - begin();				_Vec.resize(_Nw(size() + _M), 0);				_P = begin() + _O; }			copy_backward(_P, end(), end() + _M);			fill(_P, _P + _M, _X);			_Size += _M; }}	void insert(iterator _P, _It _F, _It _L)		{size_type _M = 0;		_Distance(_F, _L, _M);		if (0 < _M)			{if (capacity() - size() < _M)				{size_type _O = _P - begin();				_Vec.resize(_Nw(size() + _M), 0);				_P = begin() + _O; }			copy_backward(_P, end(), end() + _M);			copy(_F, _L, _P);			_Size += _M; }}	iterator erase(iterator _P)		{copy(_P + 1, end(), _P);		_Trim(_Size - 1);		return (_P); }	iterator erase(iterator _F, iterator _L)		{iterator _S = copy(_L, end(), _F);		_Trim(_S - begin());		return (_F); }	void clear()		{erase(begin(), end()); }	void flip()		{for (_Vbtype::iterator _S = _Vec.begin();			_S != _Vec.end(); ++_S)			*_S = ~*_S;		_Trim(_Size); }	bool _Eq(const _Myt& _X) const		{return (_Size == _X._Size && _Vec._Eq(_X._Vec)); }	bool _Lt(const _Myt& _X) const		{return (_Size < _X._Size			|| _Size == _X._Size && _Vec._Lt(_X._Vec)); }	void swap(_Myt& _X)		{std::swap(_Size, _X._Size);		_Vec.swap(_X._Vec); }	friend void swap(_Myt& _X, _Myt& _Y)		{_X.swap(_Y); }	static void swap(reference _X, reference _Y)		{bool _V = _X;		_X = _Y;		_Y = _V; }protected:	static size_type _Nw(size_type _N)		{return ((_N + _VBITS - 1) / _VBITS); }	void _Trim(size_type _N)		{size_type _M = _Nw(_N);		if (_M < _Vec.size())			_Vec.erase(_Vec.begin() + _M, _Vec.end());		_Size = _N;		_N %= _VBITS;		if (0 < _N)			_Vec[_M - 1] &= ((_Vbase)1 << _N) - 1; }	void _Xran() const		{_THROW(out_of_range, "invalid vector<bool> subscript"); }	size_type _Size;	_Vbtype _Vec;	};typedef vector<_Bool, _Bool_allocator> _Bvector;		// vector TEMPLATE OPERATORStemplate<class _Ty, class _A> inline	bool operator==(const vector<_Ty, _A>& _X,		const vector<_Ty, _A>& _Y)	{return (_X._Eq(_Y)); }template<class _Ty, class _A> inline	bool operator!=(const vector<_Ty, _A>& _X,		const vector<_Ty, _A>& _Y)	{return (!(_X == _Y)); }template<class _Ty, class _A> inline	bool operator<(const vector<_Ty, _A>& _X,		const vector<_Ty, _A>& _Y)	{return (_X._Lt(_Y)); }template<class _Ty, class _A> inline	bool operator>(const vector<_Ty, _A>& _X,		const vector<_Ty, _A>& _Y)	{return (_Y < _X); }template<class _Ty, class _A> inline	bool operator<=(const vector<_Ty, _A>& _X,		const vector<_Ty, _A>& _Y)	{return (!(_Y < _X)); }template<class _Ty, class _A> inline	bool operator>=(const vector<_Ty, _A>& _X,		const vector<_Ty, _A>& _Y)	{return (!(_X < _Y)); }_STD_END#ifdef  _MSC_VER#pragma pack(pop)#endif  /* _MSC_VER */#endif /* _VECTOR_ *//* * 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. */

⌨️ 快捷键说明

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