default (1) | explicit deque (const allocator_type& alloc = allocator_type());
|
---|---|
fill (2) | explicit deque (size_type n);
deque (size_type n, const value_type& val,
const allocator_type& alloc = allocator_type());
|
range (3) | template <class InputIterator>
deque (InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type());
|
copy (4) | deque (const deque& x);
deque (const deque& x, const allocator_type& alloc);
|
move (5) | deque (deque&& x);
deque (deque&& x, const allocator_type& alloc);
|
initializer list (6) | deque (initializer_list<value_type> il,
const allocator_type& alloc = allocator_type());
|
Constructs a deque container object, initializing its contents depending on the constructor version used:
deque容器的构造器。初始化的内容取决于以下的版本。
相应的例子:
(1)
#include <iostream> #include <deque> using namespace std; int main() { deque<int> d; cout<<"d.size="<<d.size()<<endl; cout<<"d="; for(int i:d) cout<<i<<" "; cout<<endl; }运行截图:
(2)
#include <iostream> #include <deque> using namespace std; int main() { deque<int> d(10); cout<<"d.size="<<d.size()<<endl; cout<<"d="; for(int i:d) cout<<i<<" "; cout<<endl; deque<int> d2(6,8); cout<<"d2.size="<<d.size()<<endl; cout<<"d2="; for(int i:d2) cout<<i<<" "; cout<<endl; }运行截图:
(3)
#include <iostream> #include <deque> #include <vector> using namespace std; int main() { int ar[5]={1,2,3,4,5}; deque<int> d(ar,ar+5); cout<<"d.size="<<d.size()<<endl; cout<<"d="; for(int i:d) cout<<i<<" "; cout<<endl; vector<double> vd{0.1,0.2,.05,.07,0.9}; deque<double> d2(vd.begin()+1,vd.end()); cout<<"d2.size="<<d.size()<<endl; cout<<"d2="; for(auto i:d2) cout<<i<<" "; cout<<endl; }运行截图:
(4)
#include <iostream> #include <deque> using namespace std; int main() { deque<int> d(4,5); cout<<"d.size="<<d.size()<<endl; cout<<"d="; for(int i:d) cout<<i<<" "; cout<<endl; deque<int> d2(d); cout<<"d2.size="<<d.size()<<endl; cout<<"d2="; for(auto i:d2) cout<<i<<" "; cout<<endl; }运行截图:
#include <iostream> #include <deque> using namespace std; deque<int> returnDeque(){ deque<int> d(4,5); cout<<"d.size="<<d.size()<<endl; cout<<"d="; for(int i:d) cout<<i<<" "; cout<<endl; return d; } int main() { deque<int> d2(returnDeque()); cout<<"d2.size="<<d2.size()<<endl; cout<<"d2="; for(auto i:d2) cout<<i<<" "; cout<<endl; cout<<endl<<"call returnDeque() twice!"<<endl; returnDeque(); }运行截图:
(6)
#include <iostream> #include <deque> #include <initializer_list> using namespace std; int main() { deque<int> d2({1,2,3,4,5,6,7}); cout<<"d2.size="<<d2.size()<<endl; cout<<"d2="; for(auto i:d2) cout<<i<<" "; cout<<endl; }运行截图:
Parameters
Allocator object.
The container keeps and uses an internal copy of this allocator.内存分配器对象。
容器使用该对象的拷贝。
Member type size_type is an unsigned integral type.
初始化容器的大小。
Member type value_type is the type of the elements in the container, defined in deque as an alias of its first template parameter (T).
用于填满容器内的值,容器内每个元素都将被初始化为val的拷贝。
The function template argument InputIterator shall be an input iterator type that points to elements of a type from whichvalue_type objects can be constructed.
初始化的范围的开头以及结尾的迭代器,包括first的元素,但不包括last。
Another deque object of the same type (with the same class template arguments T and Alloc), whose contents are either copied or acquired.
另一个同类型的deque(相同的模版参数)
Member type value_type is the type of the elements in the container, defined in deque as an alias of its first template parameter (T).
一个初始化列表对象。
|
|
Edit & Run
|
The contents of fifth are: 16 2 77 29 |
If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified by[first,last) is not valid, it causes undefined behavior.
——————————————————————————————————————————————————————————————————
//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:[email protected]
2014-9-1
于GDUT
——————————————————————————————————————————————————————————————————