📄 vector
字号:
return *this;
}
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template<class _InputIter>
void assign (_InputIter __first, _InputIter __last)
{ erase(begin(), end()); insert(begin(), __first, __last); }
#else
void assign (const_iterator __first, const_iterator __last)
{ erase(begin(), end()); insert(begin(), __first, __last); }
#endif
void assign (size_type __n, const bool& __t = bool())
{
erase(begin(), end()); insert(begin(), __n, __t);
}
allocator_type get_allocator() const
{
return *this;
}
//
// iterators
//
iterator begin () { return _C_start; }
const_iterator begin () const
{ return const_iterator(_C_start._C_p,_C_start._C_offset); }
iterator end () { return _C_finish; }
const_iterator end () const
{ return const_iterator(_C_finish._C_p,_C_finish._C_offset); }
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());
}
//
// capacity
//
size_type size () const { return size_type(end() - begin()); }
size_type max_size () const {
return _C_value_alloc_type(*this).max_size();
}
void resize (size_type __new_size, bool __c = false);
size_type capacity () const
{
return size_type(const_iterator(_C_end_of_storage, 0) - begin());
}
bool empty () const { return begin() == end(); }
void reserve (size_type __n)
{
_RWSTD_REQUIRES (__n <= max_size (),
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("vector<bool>::reserve (size_type)"),
__n, max_size ()));
if (capacity() < __n)
{
unsigned int* __q = _C_bit_alloc(__n);
_C_finish = _C_copy(begin(), end(), iterator(__q, 0));
_C_value_alloc_type(*this).deallocate(_C_start._C_p,
_C_end_of_storage - _C_start._C_p);
_C_start = iterator(__q, 0);
_C_end_of_storage = __q + (__n + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
}
}
//
// element access
//
reference operator[] (size_type __n)
{
#ifdef _RWSTD_BOUNDS_CHECKING
_RWSTD_REQUIRES (__n < size (),
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("vector<bool>::[](size_type)"),
__n, size ()));
#endif // _RWSTD_BOUNDS_CHECKING
return *(begin() + __n);
}
const_reference operator[] (size_type __n) const
{
#ifdef _RWSTD_BOUNDS_CHECKING
_RWSTD_REQUIRES (__n < size (),
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("vector<bool>::[](size_type)"),
__n, size ()));
#endif // _RWSTD_BOUNDS_CHECKING
return *(begin() + __n);
}
reference at (size_type __n)
{
_RWSTD_REQUIRES (__n < size (),
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("vector<bool>::at(size_type)"),
__n, size ()));
return *(begin() + __n);
}
const_reference at (size_type __n) const
{
_RWSTD_REQUIRES (__n < size (),
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("vector<bool>::at(size_type) const"),
__n, size ()));
return *(begin() + __n);
}
reference front () { return *begin(); }
const_reference front () const { return *begin(); }
reference back () { return *(end() - 1); }
const_reference back () const { return *(end() - 1); }
//
// modifiers
//
void push_back (const bool& __x)
{
if (_C_finish._C_p != _C_end_of_storage) {
++_C_finish;
*(_C_finish-1) = __x;
}
else
_C_insert_aux(end(), __x);
}
void pop_back () { --_C_finish; }
iterator insert (iterator __position, const bool& __x = bool())
{
size_type __n = __position - begin();
if (_C_finish._C_p != _C_end_of_storage && __position == end()) {
++_C_finish;
*(_C_finish-1) = __x;
}
else
_C_insert_aux(__position, __x);
return begin() + __n;
}
void insert (iterator __position, size_type __n, const bool& __x);
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template<class _InputIter>
void insert (iterator __position, _InputIter __first,
_InputIter __last);
#else
void insert (iterator __position, const_iterator __first,
const_iterator __last);
#endif
iterator erase (iterator __position)
{
if (!(__position + 1 == end()))
_C_copy(__position + 1, end(), __position);
--_C_finish;
return __position;
}
iterator erase(iterator __first, iterator __last)
{
_C_finish = _C_copy(__last, end(), __first);
return __first;
}
void swap (_C_self& __x)
{
if((_C_value_alloc_type)*this == (_C_value_alloc_type)__x)
{
_STD::swap (_C_start, __x._C_start);
_STD::swap (_C_finish, __x._C_finish);
_STD::swap (_C_end_of_storage, __x._C_end_of_storage);
}
else
{
_C_self _x = *this;
*this = __x;
__x=_x;
}
}
static void swap(reference __x, reference __y);
void flip ();
void clear()
{
erase(begin(),end());
}
};
#ifndef _RWSTD_NO_FUNC_PARTIAL_SPEC
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
template <class _Allocator>
#endif
inline bool operator== (const vector<bool,_Allocator >& __x,
const vector<bool,_Allocator >& __y)
{
if (__x.size() == __y.size())
{
_TYPENAME vector<bool,_Allocator >::const_iterator
first1 = __x.begin(),
last1 = __x.end(),
first2 = __y.begin();
while (first1 != last1 && *first1 == *first2)
{
++first1;
++first2;
}
return first1 == last1;
}
return false;
}
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
template <class _Allocator>
#endif
inline bool operator< (const vector<bool,_Allocator >& __x,
const vector<bool,_Allocator >& __y)
{
_TYPENAME vector<bool,_Allocator >::const_iterator
first1 = __x.begin(),
last1 = __x.end(),
first2 = __y.begin(),
last2 = __y.end();
while (first1 != last1 && first2 != last2)
{
if ((int)*first1 < (int)*first2) return true;
if ((int)*first2++ < (int)*first1++) return false;
}
return first1 == last1 && first2 != last2;
}
#else
_RWSTD_SPECIALIZED_FUNCTION
inline bool operator== (const vector<bool,allocator<bool> >& __x,
const vector<bool,allocator<bool> >& __y)
{
if (__x.size() == __y.size())
{
vector<bool,allocator<bool> >::const_iterator
first1 = __x.begin(),
last1 = __x.end(),
first2 = __y.begin();
while (first1 != last1 && *first1 == *first2)
{
++first1;
++first2;
}
return first1 == last1;
}
return false;
}
_RWSTD_SPECIALIZED_FUNCTION
inline bool operator< (const vector<bool,allocator<bool> >& __x,
const vector<bool,allocator<bool> >& __y)
{
vector<bool,allocator<bool> >::const_iterator
first1 = __x.begin(),
last1 = __x.end(),
first2 = __y.begin(),
last2 = __y.end();
while (first1 != last1 && first2 != last2)
{
if ((int)*first1 < (int)*first2) return true;
if ((int)*first2++ < (int)*first1++) return false;
}
return first1 == last1 && first2 != last2;
}
#endif
#ifndef _RWSTD_NO_FUNC_PARTIAL_SPEC
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
template <class _Allocator>
#endif
inline bool operator!= (const vector<bool,_Allocator >& __x,
const vector<bool,_Allocator >& __y)
{
return !(__x == __y);
}
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
template <class _Allocator>
#endif
inline bool operator> (const vector<bool,_Allocator >& __x,
const vector<bool,_Allocator >& __y)
{
return __y < __x;
}
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
template <class _Allocator>
#endif
inline bool operator>= (const vector<bool,_Allocator >& __x,
const vector<bool,_Allocator >& __y)
{
return !(__x < __y);
}
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
template <class _Allocator>
#endif
inline bool operator<= (const vector<bool,_Allocator >& __x,
const vector<bool,_Allocator >& __y)
{
return !(__y < __x);
}
#ifndef _RWSTD_NO_PART_SPEC_OVERLOAD
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
template <class _Allocator>
#endif
inline void swap(vector<bool,_Allocator >& __a, vector<bool,_Allocator >& __b)
{
__a.swap(__b);
}
#endif
#else //_RWSTD_NO_FUNC_PART_SPEC
_RWSTD_SPECIALIZED_FUNCTION
inline bool operator!= (const vector<bool,allocator<bool> >& __x,
const vector<bool,allocator<bool> >& __y)
{
return !(__x == __y);
}
_RWSTD_SPECIALIZED_FUNCTION
inline bool operator> (const vector<bool,allocator<bool> >& __x,
const vector<bool,allocator<bool> >& __y)
{
return __y < __x;
}
_RWSTD_SPECIALIZED_FUNCTION
inline bool operator>= (const vector<bool,allocator<bool> >& __x,
const vector<bool,allocator<bool> >& __y)
{
return !(__x < __y);
}
_RWSTD_SPECIALIZED_FUNCTION
inline bool operator<= (const vector<bool,allocator<bool> >& __x,
const vector<bool,allocator<bool> >& __y)
{
return !(__y < __x);
}
_RWSTD_SPECIALIZED_FUNCTION
inline void swap (vector<bool, allocator<bool> >& __a,
vector<bool, allocator<bool> >& __b)
{
__a.swap(__b);
}
#endif
#undef _Allocator
#endif // _RWSTD_NO_BOOL
#endif // _RWSTD_NO_VECTOR_BOOL
_RWSTD_NAMESPACE_END // std
#if defined (_RWSTD_COMPILE_INSTANTIATE)
# include <vector.cc>
#endif
#ifndef _RWSTD_NO_STL_SPECIALIZATION
#include "vector_spec.h"
#endif // _RWSTD_NO_STL_SPECIALIZATION
#endif // _RWSTD_VECTOR_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -