📄 vector
字号:
&& equal(_Left.begin(), _Left.end(), _Right.begin()));
}
template<class _Ty,
class _Alloc> inline
bool operator!=(const vector<_Ty, _Alloc>& _Left,
const vector<_Ty, _Alloc>& _Right)
{ // test for vector inequality
return (!(_Left == _Right));
}
template<class _Ty,
class _Alloc> inline
bool operator<(const vector<_Ty, _Alloc>& _Left,
const vector<_Ty, _Alloc>& _Right)
{ // test if _Left < _Right for vectors
return (lexicographical_compare(_Left.begin(), _Left.end(),
_Right.begin(), _Right.end()));
}
template<class _Ty,
class _Alloc> inline
bool operator>(const vector<_Ty, _Alloc>& _Left,
const vector<_Ty, _Alloc>& _Right)
{ // test if _Left > _Right for vectors
return (_Right < _Left);
}
template<class _Ty,
class _Alloc> inline
bool operator<=(const vector<_Ty, _Alloc>& _Left,
const vector<_Ty, _Alloc>& _Right)
{ // test if _Left <= _Right for vectors
return (!(_Right < _Left));
}
template<class _Ty,
class _Alloc> inline
bool operator>=(const vector<_Ty, _Alloc>& _Left,
const vector<_Ty, _Alloc>& _Right)
{ // test if _Left >= _Right for vectors
return (!(_Left < _Right));
}
//
// TEMPLATE CLASS vector<bool, Alloc> AND FRIENDS
//
typedef unsigned int _Vbase; // word type for vector<bool> representation
const int _VBITS = 8 * sizeof (_Vbase); // at least CHAR_BITS bits per word
// CLASS _Vb_iter_base
template<class _Alloc>
class _Vb_iter_base
: public _Iterator012<random_access_iterator_tag,
_Bool,
typename _Alloc::difference_type,
bool *,
bool,
_Iterator_base>
{ // store information common to reference and iterators
public:
typedef typename _Alloc::size_type _Sizet;
typedef vector<_Bool, _Alloc> _Mycont;
_Vb_iter_base()
: _Myptr(0), _Myoff(0)
{ // construct with null pointer
}
_Vb_iter_base(const _Vbase *_Ptr, _Sizet _Off,
const _Container_base *_Mypvbool)
: _Myptr(_Ptr), _Myoff(_Off)
{ // construct with offset and pointer
this->_Adopt(_Mypvbool);
}
int _Valid(_Sizet _Inc) const
{ // test for valid incremented offset
#if _ITERATOR_DEBUG_LEVEL == 2
_Sizet _Mysize = ((_Mycont *)this->_Getcont())->_Mysize;
_Inc += _Myoff;
_Inc += _VBITS * (_Myptr
- (((_Mycont *)this->_Getcont())->_Myvec)._Myfirst);
return (_Inc < _Mysize ? -1 : _Inc == _Mysize ? 0 : +1);
#else /* _ITERATOR_DEBUG_LEVEL == 2 */
return (-1);
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
}
const _Vbase *_Myptr;
_Sizet _Myoff;
};
// CLASS _Vb_reference
template<class _Alloc>
class _Vb_reference
: public _Vb_iter_base<_Alloc>
{ // reference to a bit within a base word
public:
typedef _Vb_iter_base<_Alloc> _Mybase;
typedef _Vb_reference<_Alloc> _Mytype;
_Vb_reference()
{ // construct with null pointer
}
_Vb_reference(const _Mybase& _Right)
: _Mybase(_Right._Myptr, _Right._Myoff, _Right._Getcont())
{ // construct with base
}
_Mytype& operator=(const _Mytype& _Right)
{ // assign _Vb_reference _Right to bit
return (*this = bool(_Right));
}
_Mytype& operator=(bool _Val)
{ // assign _Val to bit
if (_Val)
*(_Vbase *)_Getptr() |= _Mask();
else
*(_Vbase *)_Getptr() &= ~_Mask();
return (*this);
}
void flip()
{ // toggle the bit
*(_Vbase *)_Getptr() ^= _Mask();
}
bool operator~() const
{ // test if bit is reset
return (!bool(*this));
}
operator bool() const
{ // test if bit is set
return ((*_Getptr() & _Mask()) != 0);
}
const _Vbase *_Getptr() const
{ // get pointer to base word
#if _ITERATOR_DEBUG_LEVEL == 2
if (this->_Getcont() == 0
|| this->_Myptr == 0
|| 0 <= this->_Valid(0))
{ // report error
_DEBUG_ERROR("vector<bool> iterator not dereferencable");
_SCL_SECURE_OUT_OF_RANGE;
}
#elif _ITERATOR_DEBUG_LEVEL == 1
_SCL_SECURE_VALIDATE(this->_Getcont() != 0 && this->_Myptr != 0);
_SCL_SECURE_VALIDATE_RANGE(this->_Valid(0) < 0);
#endif /* _ITERATOR_DEBUG_LEVEL */
return (this->_Myptr);
}
protected:
_Vbase _Mask() const
{ // convert offset to mask
return ((_Vbase)(1 << this->_Myoff));
}
};
template<class _Alloc>
void swap(_Vb_reference<_Alloc> _Left,
_Vb_reference<_Alloc> _Right)
{ // swap _Left and _Right vector<bool> elements
bool _Val = _Left; // NOT _STD swap
_Left = _Right;
_Right = _Val;
}
// CLASS _Vb_const_iterator
template<class _Alloc>
class _Vb_const_iterator
: public _Vb_iter_base<_Alloc>
{ // iterator for nonmutable vector<bool>
public:
typedef _Vb_iter_base<_Alloc> _Mybase;
typedef _Vb_const_iterator<_Alloc> _Mytype;
typedef _Vb_reference<_Alloc> _Reft;
typedef bool const_reference;
typedef random_access_iterator_tag iterator_category;
typedef _Bool value_type;
typedef typename _Alloc::size_type size_type;
typedef typename _Alloc::difference_type difference_type;
typedef const_reference *pointer;
typedef const_reference reference;
_Vb_const_iterator()
{ // construct with null reference
}
_Vb_const_iterator(const _Vbase *_Ptr, const _Container_base *_Mypvbool)
: _Mybase(_Ptr, 0, _Mypvbool)
{ // construct with offset and pointer
}
const_reference operator*() const
{ // return (reference to) designated object
return (_Reft(*this));
}
_Mytype& operator++()
{ // preincrement
_Inc();
return (*this);
}
_Mytype operator++(int)
{ // postincrement
_Mytype _Tmp = *this;
++*this;
return (_Tmp);
}
_Mytype& operator--()
{ // predecrement
_Dec();
return (*this);
}
_Mytype operator--(int)
{ // postdecrement
_Mytype _Tmp = *this;
--*this;
return (_Tmp);
}
_Mytype& operator+=(difference_type _Off)
{ // increment by integer
if (_Off < 0 && this->_Myoff < 0 - (size_type)_Off)
{ /* add negative increment */
this->_Myoff += _Off;
this->_Myptr -= 1 + ((size_type)(-1) - this->_Myoff) / _VBITS;
this->_Myoff %= _VBITS;
}
else
{ /* add non-negative increment */
this->_Myoff += _Off;
this->_Myptr += this->_Myoff / _VBITS;
this->_Myoff %= _VBITS;
}
return (*this);
}
_Mytype operator+(difference_type _Off) const
{ // return this + integer
_Mytype _Tmp = *this;
return (_Tmp += _Off);
}
_Mytype& operator-=(difference_type _Off)
{ // decrement by integer
return (*this += -_Off);
}
_Mytype operator-(difference_type _Off) const
{ // return this - integer
_Mytype _Tmp = *this;
return (_Tmp -= _Off);
}
difference_type operator-(
const _Mytype& _Right) const
{ // return difference of iterators
_Compat(_Right);
return (_VBITS * (this->_Myptr - _Right._Myptr)
+ (difference_type)this->_Myoff
- (difference_type)_Right._Myoff);
}
const_reference operator[](difference_type _Off) const
{ // subscript
return (*(*this + _Off));
}
bool operator==(const _Mytype& _Right) const
{ // test for iterator equality
_Compat(_Right);
return (this->_Myptr == _Right._Myptr
&& this->_Myoff == _Right._Myoff);
}
bool operator!=(const _Mytype& _Right) const
{ // test for iterator inequality
return (!(*this == _Right));
}
bool operator<(const _Mytype& _Right) const
{ // test if this < _Right
_Compat(_Right);
return (this->_Myptr < _Right._Myptr
|| this->_Myptr == _Right._Myptr
&& this->_Myoff < _Right._Myoff);
}
bool operator>(const _Mytype& _Right) const
{ // test if this > _Right
return (_Right < *this);
}
bool operator<=(const _Mytype& _Right) const
{ // test if this <= _Right
return (!(_Right < *this));
}
bool operator>=(const _Mytype& _Right) const
{ // test if this >= _Right
return (!(*this < _Right));
}
#if _ITERATOR_DEBUG_LEVEL == 2
void _Compat(const _Mytype& _Right) const
{ // test for compatible iterator pair
if (this->_Getcont() == 0
|| this->_Getcont() != _Right._Getcont())
_DEBUG_ERROR("vector<bool> iterators incompatible");
}
#elif _ITERATOR_DEBUG_LEVEL == 1
void _Compat(const _Mytype& _Right) const
{ // test for compatible iterator pair
_SCL_SECURE_VALIDATE(this->_Getcont() != 0);
_SCL_SECURE_VALIDATE_RANGE(this->_Getcont() == _Right._Getcont());
}
#else /* _ITERATOR_DEBUG_LEVEL == 0 */
void _Compat(const _Mytype&) const
{ // test for compatible iterator pair
}
#endif /* _ITERATOR_DEBUG_LEVEL */
void _Dec()
{ // decrement bit position
if (this->_Myoff != 0)
--this->_Myoff;
else
{ // move to previous word
#if _ITERATOR_DEBUG_LEVEL == 2
if (this->_Getcont() == 0 || 0 < this->_Valid((size_type)-1))
{ // report error
_DEBUG_ERROR("vector<bool> iterator not decrementable");
_SCL_SECURE_OUT_OF_RANGE;
}
#elif _ITERATOR_DEBUG_LEVEL == 1
_SCL_SECURE_VALIDATE(this->_Getcont() != 0);
_SCL_SECURE_VALIDATE_RANGE(this->_Valid((size_type)-1) <= 0);
#endif /* _ITERATOR_DEBUG_LEVEL */
this->_Myoff = _VBITS - 1;
--this->_Myptr;
}
}
void _Inc()
{ // increment bit position
if (this->_Myoff < _VBITS - 1)
++this->_Myoff;
else
{ // move to next word
#if _ITERATOR_DEBUG_LEVEL == 2
if (this->_Getcont() == 0 || 0 < this->_Valid(1))
{ // report error
_DEBUG_ERROR("vector<bool> iterator not incrementable");
_SCL_SECURE_OUT_OF_RANGE;
}
#elif _ITERATOR_DEBUG_LEVEL == 1
_SCL_SECURE_VALIDATE(this->_Getcont() != 0);
_SCL_SECURE_VALIDATE_RANGE(this->_Valid(1) <= 0);
#endif /* _ITERATOR_DEBUG_LEVEL */
this->_Myoff = 0;
++this->_Myptr;
}
}
};
template<class _Alloc>
_Vb_const_iterator<_Alloc> operator+(
typename _Alloc::difference_type _Off,
_Vb_const_iterator<_Alloc> _Right)
{ // return _Right + integer
return (_Right += _Off);
}
template<class _Alloc>
struct _Is_checked_helper<_Vb_const_iterator<_Alloc> >
: public _STD tr1::true_type
{ // mark _Vb_const_iterator as checked
};
// CLASS _Vb_iterator
template<class _Alloc>
class _Vb_iterator
: public _Vb_const_iterator<_Alloc>
{ // iterator for mutable vector<bool>
public:
typedef _Vb_const_iterator<_Alloc> _Mybase;
typedef _Vb_iterator<_Alloc> _Mytype;
typedef _Vb_reference<_Alloc> _Reft;
typedef bool const_reference;
typedef random_access_iterator_tag iterator_category;
typedef _Bool value_type;
typedef typename _Alloc::size_type size_type;
typedef typename _Alloc::difference_type difference_type;
typedef _Reft *pointer;
typedef _Reft reference;
_Vb_iterator()
{ // construct with null reference
}
_Vb_iterator(_Vbase *_Ptr, _Container_base *_Mypvbool)
: _Mybase(_Ptr, _Mypvbool)
{ // construct with offset and pointer
}
reference operator*() const
{ // return (reference to) designated object
return (_Reft(*this));
}
_Mytype& operator++()
{ // preincrement
++*(_Mybase *)this;
return (*this);
}
_Mytype operator++(int)
{ // postincrement
_Mytype _Tmp = *this;
++*this;
return (_Tmp);
}
_Mytype& operator--()
{ // predecrement
--*(_Mybase *)this;
return (*this);
}
_Mytype operator--(int)
{ // postdecrement
_Mytype _Tmp = *this;
--*this;
return (_Tmp);
}
_Mytype& operator+=(difference_type _Off)
{ // increment by integer
*(_Mybase *)this += _Off;
return (*this);
}
_Mytype operator+(difference_type _Off) const
{ // return this + integer
_Mytype _Tmp = *this;
return (_Tmp += _Off);
}
_Mytype& operator-=(difference_type _Off)
{ // decrement by integer
return (*this += -_Off);
}
_Mytype operator-(difference_type _Off) const
{ // return this - integer
_Mytype _Tmp = *this;
return (_Tmp -= _Off);
}
difference_type operator-(const _Mybase& _Right) const
{ // return difference of iterators
return (*(_Mybase *)this - _Right);
}
reference operator[](difference_type _Off) const
{ // subscript
return (*(*this + _Off));
}
};
template<class _Alloc>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -