//默认构造构造函数
list() : _Mypair(_Zero_then_variadic_args_t{}) {
//调用下面函数
_Alloc_sentinel_and_proxy();
}
void _Alloc_sentinel_and_proxy() {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
auto& _Al = _Getal();
//申请内存空间
auto _Newhead = _Al.allocate(1);
_Construct_in_place(_Newhead->_Next, _Newhead);
_Construct_in_place(_Newhead->_Prev, _Newhead);
//将指向头指针
_Mypair._Myval2._Myhead = _Newhead;
_Proxy._Release();
}
//List 模板类中的类属性,定义了一个对象 _Mypair
_Compressed_pair<_Alnode, _Scary_val> _Mypair;
//在 _Compressed_pair类中定义了一个对象 _Scary_val
template <class _Ty1, class _Ty2, bool = is_empty_v<_Ty1> && !is_final_v<_Ty1>>
class _Compressed_pair final : private _Ty1 { // store a pair of values, deriving from empty first
public:
_Ty2 _Myval2;
..........
}
using _Scary_val = _List_val<_Val_types>;
//_Scary_val 对象中包含了下面主要的两个类属性
//头指针
_Nodeptr _Myhead; // pointer to head node
//存放元素大小
size_type _Mysize; // number of elements
//deque 构造函数
deque() : _Mypair(_Zero_then_variadic_args_t{}) {
_Get_data()._Alloc_proxy(static_cast<_Alproxy_ty>(_Getal()));
}
//deque 中的唯一类属性
_Compressed_pair<_Alty, _Scary_val> _Mypair;
//
using _Scary_val = _Deque_val<conditional_t<_Is_simple_alloc_v<_Alty>, _Deque_simple_types<_Ty>,
_Deque_iter_types<_Ty, typename _Alty_traits::size_type, typename _Alty_traits::difference_type,
typename _Alty_traits::pointer, typename _Alty_traits::const_pointer, _Ty&, const _Ty&, _Mapptr>>>;
//_Deque_val类中的主要属性
//篮子数组的指针
_Mapptr _Map; // pointer to array of pointers to blocks
//篮子的大小
size_type _Mapsize; // size of map array, zero or 2^N
//???
size_type _Myoff; // offset of initial element
//元素个数
size_type _Mysize; // current length of sequence
队列和栈的实现都是基于deque
原文:https://www.cnblogs.com/yanggang98/p/14181701.html