📄 deque
字号:
: allocator_type (__alloc), _C_map_size (0) {
_C_init ();
insert (begin (), __n, __val);
}
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template<class _InputIter>
deque (_InputIter __first, _InputIter __last,
const allocator_type& __al = allocator_type ())
: allocator_type (__al), _C_map_size (0) {
_C_init ();
_RWSTD_ASSERT_RANGE (__first, __last);
typedef _TYPENAME _RWdispatch<_InputIter>::_RWtype _RWtype;
__insert_aux (begin (), __first, __last, _RWtype ());
}
#else // if defined (_RWSTD_NO_MEMBER_TEMPLATES)
deque (const_iterator __first, const_iterator __last,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc), _C_map_size (0) {
_C_init ();
_RWSTD_ASSERT_RANGE (__first, __last);
copy (__first, __last, back_inserter (*this));
}
deque (const_pointer __first, const_pointer __last,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc), _C_map_size (0) {
_C_init ();
_RWSTD_ASSERT_RANGE (__first, __last);
copy (__first, __last, back_inserter (*this));
}
#endif // _RWSTD_NO_MEMBER_TEMPLATES
deque (const deque &__x)
: allocator_type (__x.get_allocator ()), _C_map_size (0) {
_C_init ();
copy (__x.begin (), __x.end (), back_inserter (*this));
}
~deque () {
while (!empty ())
pop_front ();
}
deque& operator= (const deque &__x) {
if (this != &__x) {
if (size () >= __x.size ())
erase (copy (__x.begin (), __x.end (), begin ()), end ());
else
copy (__x.begin () + size (), __x.end (),
inserter (*this,
copy (__x.begin (),
__x.begin () + size (), begin ())));
}
return *this;
}
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template<class _InputIter>
void assign (_InputIter __first, _InputIter __last) {
_RWSTD_ASSERT_RANGE (__first, __last);
clear ();
typedef _TYPENAME _RWdispatch<_InputIter>::_RWtype _RWtype;
__insert_aux (begin (), __first, __last, _RWtype ());
}
void assign (size_type __n, const_reference __t) {
clear ();
insert (begin (), __n, __t);
}
#else // if defined (_RWSTD_NO_MEMBER_TEMPLATES)
void assign (const_iterator __first, const_iterator __last) {
_RWSTD_ASSERT_RANGE (__first, __last);
clear ();
insert (begin (), __first, __last);
}
void assign (const_pointer __first, const_pointer __last) {
clear ();
insert (begin (), __first, __last);
}
void assign (size_type __n, const_reference __x) {
clear ();
insert (begin (), __n, __x);
}
#endif // _RWSTD_NO_MEMBER_TEMPLATES
allocator_type get_allocator () const {
return *this;
}
iterator begin () {
return _C_make_iter (_C_begin);
}
const_iterator begin () const {
return _C_make_iter (_C_begin);
}
iterator end () {
return _C_make_iter(_C_end);
}
const_iterator end () const {
return _C_make_iter (_C_end);
}
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 ());
}
bool empty () const {
return 0 == size ();
}
size_type size () const {
return _C_size;
}
size_type max_size () const {
return _RWSTD_VALUE_ALLOC (_C_value_alloc_type, max_size ());
}
void resize (size_type, value_type);
void resize (size_type __size) {
resize (__size, value_type ());
}
reference operator[] (size_type __n) {
#ifdef _RWSTD_BOUNDS_CHECKING
return at (__n);
#else
return *(begin () + __n);
#endif
}
const_reference operator[] (size_type __n) const {
#ifdef _RWSTD_BOUNDS_CHECKING
return at (__n);
#else
return *(begin () + __n);
#endif
}
const_reference at (size_type __n) const {
return _RWSTD_CONST_CAST (deque*, this)->at (__n);
}
reference at (size_type __n) {
_RWSTD_REQUIRES (__n < size (),
(_RWSTD_ERROR_OUT_OF_RANGE,
_RWSTD_FUNC ("deque::at(size_type)"), __n, size ()));
return *(begin () + __n);
}
reference front () {
_RWSTD_ASSERT (!empty ());
return *begin ();
}
const_reference front () const {
_RWSTD_ASSERT (!empty ());
return *begin ();
}
reference back () {
_RWSTD_ASSERT (!empty ());
return *(end () - 1);
}
const_reference back () const {
_RWSTD_ASSERT (!empty ());
return *(end () - 1);
}
void push_front (const_reference);
void push_back (const_reference);
iterator insert (iterator, const_reference);
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template <class _InputIter>
void insert (iterator __pos, _InputIter __first, _InputIter __last) {
insert (__pos, __first, __last, _RWSTD_DISPATCH (_InputIter));
}
template <class _InputIter>
void insert (iterator __pos, _InputIter __first, _InputIter __last,
_RWSTD_DISPATCH_INT (false)) {
_RWSTD_ASSERT_RANGE (begin (), __pos);
_RWSTD_ASSERT_RANGE (__first, __last);
__insert_interval_dispatch (__pos, __first, __last,
_RWSTD_ITERATOR_CATEGORY (_InputIter,
__first));
}
void insert (iterator __pos, size_type __n, const_reference __val,
_RWSTD_DISPATCH_INT (true) = 0) {
__insert_aux (__pos, __n, __val);
}
#else // if defined (_RWSTD_NO_MEMBER_TEMPLATES)
void insert (iterator __pos, size_type __n, const_reference __val) {
__insert_aux (__pos, __n, __val);
}
void insert (iterator, const_pointer, const_pointer);
void insert (iterator, const_iterator, const_iterator);
#endif // _RWSTD_NO_MEMBER_TEMPLATES
void pop_front ();
void pop_back ();
iterator erase (iterator);
iterator erase (iterator, iterator);
void swap (deque &);
void clear () {
erase (begin (), end ());
_RWSTD_ASSERT (empty ());
}
};
template <class _TypeT, class _Allocator>
inline void
deque<_TypeT, _Allocator>::push_front (const_reference __val)
{
if ( empty ()
|| _C_begin._C_current == _C_begin._C_first)
_C_alloc_at_begin ();
--_C_begin._C_current;
_RWSTD_VALUE_ALLOC (_C_value_alloc_type,
construct (_C_begin._C_current, __val));
++_C_size;
_RWSTD_ASSERT (!empty ());
}
template <class _TypeT, class _Allocator>
inline void
deque<_TypeT, _Allocator>::push_back (const_reference __val)
{
if ( empty ()
|| _C_end._C_current == _C_end._C_last)
_C_alloc_at_end ();
_RWSTD_VALUE_ALLOC (_C_value_alloc_type,
construct (_C_end._C_current, __val));
++_C_end._C_current;
++_C_size;
_RWSTD_ASSERT (!empty ());
}
template <class _TypeT, class _Allocator>
inline void
deque<_TypeT, _Allocator>::pop_front ()
{
_RWSTD_ASSERT (!empty ());
_C_deque_iter __tmp = _C_begin;
++_C_begin._C_current;
--_C_size;
_RWSTD_VALUE_ALLOC (_C_value_alloc_type,
destroy (__tmp._C_current));
if ( empty ()
|| _C_begin._C_current == _C_begin._C_last)
_C_free_at_begin ();
}
template <class _TypeT, class _Allocator>
inline void
deque<_TypeT, _Allocator>::pop_back ()
{
_RWSTD_ASSERT (!empty ());
--_C_end._C_current;
--_C_size;
_RWSTD_VALUE_ALLOC (_C_value_alloc_type,
destroy (_C_end._C_current));
if ( empty ()
|| _C_end._C_current == _C_end._C_first)
_C_free_at_end ();
}
template <class _TypeT, class _Allocator>
inline void
deque<_TypeT, _Allocator>::swap (deque<_TypeT, _Allocator>& __x)
{
if (get_allocator () == __x.get_allocator ()) {
_STD::swap (_C_begin, __x._C_begin);
_STD::swap (_C_end, __x._C_end);
_STD::swap (_C_size, __x._C_size);
_STD::swap (_C_map, __x._C_map);
_STD::swap (_C_map_size, __x._C_map_size);
}
else {
deque __tmp = *this;
*this = __x;
__x = __tmp;
}
}
template <class _TypeT, class _Allocator>
inline bool
operator== (const deque<_TypeT, _Allocator>& __x,
const deque<_TypeT, _Allocator>& __y)
{
return __x.size () == __y.size ()
&& equal (__x.begin (), __x.end (), __y.begin ());
}
template <class _TypeT, class _Allocator>
inline bool
operator< (const deque<_TypeT, _Allocator>& __x,
const deque<_TypeT, _Allocator>& __y)
{
return lexicographical_compare (__x.begin (), __x.end (),
__y.begin (), __y.end ());
}
template <class _TypeT, class _Allocator>
inline bool
operator!= (const deque<_TypeT, _Allocator>& __x,
const deque<_TypeT, _Allocator>& __y)
{
return !(__x == __y);
}
template <class _TypeT, class _Allocator>
inline bool
operator<= (const deque<_TypeT, _Allocator>& __x,
const deque<_TypeT, _Allocator>& __y)
{
return !(__y < __x);
}
template <class _TypeT, class _Allocator>
inline bool
operator> (const deque<_TypeT, _Allocator>& __x,
const deque<_TypeT, _Allocator>& __y)
{
return __y < __x;
}
template <class _TypeT, class _Allocator>
inline bool
operator>= (const deque<_TypeT, _Allocator>& __x,
const deque<_TypeT, _Allocator>& __y)
{
return !(__x < __y);
}
template <class _TypeT, class _Allocator>
inline void
deque<_TypeT, _Allocator>::resize (size_type __size, value_type __val)
{
if (__size > size ())
insert (end (), __size - size (), __val);
else if (__size < size ())
erase (begin () + __size, end ());
}
_RWSTD_NAMESPACE_END // end
#ifdef _RWSTD_COMPILE_INSTANTIATE
# include <deque.cc>
#endif
#ifndef _RWSTD_NO_STL_SPECIALIZATION
# include "deque_spec.h"
#endif // _RWSTD_NO_STL_SPECIALIZATION
#endif // _RWSTD_DEQUE_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -