deque::deque
构造满足下列条件之一的双端队列:具有特定的大小;具有特定值的元素;具有特定的分配器;是所有其他列表的副本或是其他一些双端队列的一部分的副本。
deque( );
explicit deque(
const Allocator& Al
);
explicit deque(
size_type Count
);
deque(
size_type Count,
const Type& Val
);
deque(
size_type Count,
const Type& Val,
const Allocator& Al
);
deque(
const deque& Right
);
template<class InputIterator>
deque(
InputIterator First,
InputIterator Last
);
template<class InputIterator>
deque(
InputIterator First,
InputIterator Last,
const Allocator& Al
);
deque(
initializer_list<value_type> IList,
const Allocator& Al
);
参数
参数 |
说明 |
Al |
要用于此对象的分配器类。 |
Count |
构造双端队列中的元素数。 |
Val |
构造双端队列中的元素的值。 |
Right |
用于拷贝构造双端队列的双端队列。 |
First |
要复制的元素范围中的第一个元素的位置。 |
Last |
要复制的元素范围之外的第一个元素的位置。 |
IList |
要复制的 initializer_list。 |
备注
所有构造函数存储一个分配器对象 (Al) 并初始化双端队列。
前两个构造函数指定空的初始双端队列,其中第二个指定要使用的分配器类型 (_Al)。
第三个构造函数指定重复“类型”类的默认值的元素指定次数 (_Count)。 Type
第四和第五个构造函数 _Val 的元素 (Count) 次。
第六个构造函数指定 Right 双端队列的副本。
第七个及第八个构造函数复制双端队列的范围 [First, Last)。
第七个构造函数将双端队列移动到 Right。
第八个构造函数复制 initializer_list 的内容。
构造函数都不执行任何临时重新发布。
示例
/ compile with: /EHsc
#include <deque>
#include <iostream>
#include <forward_list>
int main()
{
using namespace std;
forward_list<int> f1{ 1, 2, 3, 4 };
f1.insert_after(f1.begin(), { 5, 6, 7, 8 });
deque <int>::iterator c1_Iter, c2_Iter, c3_Iter, c4_Iter, c5_Iter, c6_Iter;
// Create an empty deque c0
deque <int> c0;
// Create a deque c1 with 3 elements of default value 0
deque <int> c1(3);
// Create a deque c2 with 5 elements of value 2
deque <int> c2(5, 2);
// Create a deque c3 with 3 elements of value 1 and with the
// allocator of deque c2
deque <int> c3(3, 1, c2.get_allocator());
// Create a copy, deque c4, of deque c2
deque <int> c4(c2);
// Create a deque c5 by copying the range c4[_First, _Last)
c4_Iter = c4.begin();
c4_Iter++;
c4_Iter++;
deque <int> c5(c4.begin(), c4_Iter);
// Create a deque c6 by copying the range c4[_First, _Last) and
// c2 with the allocator of deque
c4_Iter = c4.begin();
c4_Iter++;
c4_Iter++;
c4_Iter++;
deque <int> c6(c4.begin(), c4_Iter, c2.get_allocator());
// Create a deque c8 by copying the contents of an initializer_list
// using brace initialization
deque<int> c8({ 1, 2, 3, 4 });
initializer_list<int> iList{ 5, 6, 7, 8 };
deque<int> c9( iList);
cout << "c1 = ";
for (int i : c1)
cout << i << " ";
cout << endl;
cout << "c2 = ";
for (int i : c2)
cout << i << " ";
cout << endl;
cout << "c3 = ";
for (int i : c3)
cout << i << " ";
cout << endl;
cout << "c4 = ";
for (int i : c4)
cout << i << " ";
cout << endl;
cout << "c5 = ";
for (int i : c5)
cout << i << " ";
cout << endl;
cout << "c6 = ";
for (int i : c6)
cout << i << " ";
cout << endl;
// Move deque c6 to deque c7
deque <int> c7(move(c6));
deque <int>::iterator c7_Iter;
cout << "c7 =";
for (int i : c7)
cout << i << " ";
cout << endl;
cout << "c8 = ";
for (int i : c8)
cout << i << " ";
cout << endl;
cout << "c9 = ";
for (int i : c9)
cout << i << " ";
cout << endl;
int x = 3;
}
// deque_deque.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>
int main( )
{
using namespace std;
deque <int>::iterator c1_Iter, c2_Iter, c3_Iter, c4_Iter, c5_Iter, c6_Iter;
// Create an empty deque c0
deque <int> c0;
// Create a deque c1 with 3 elements of default value 0
deque <int> c1( 3 );
// Create a deque c2 with 5 elements of value 2
deque <int> c2( 5, 2 );
// Create a deque c3 with 3 elements of value 1 and with the
// allocator of deque c2
deque <int> c3( 3, 1, c2.get_allocator( ) );
// Create a copy, deque c4, of deque c2
deque <int> c4( c2 );
// Create a deque c5 by copying the range c4[_First, _Last)
c4_Iter = c4.begin( );
c4_Iter++;
c4_Iter++;
deque <int> c5( c4.begin( ), c4_Iter );
// Create a deque c6 by copying the range c4[_First, _Last) and
// c2 with the allocator of deque
c4_Iter = c4.begin( );
c4_Iter++;
c4_Iter++;
c4_Iter++;
deque <int> c6( c4.begin( ), c4_Iter, c2.get_allocator( ) );
// Create a deque c8 by copying the contents of an initializer_list
// using brace initialization
deque<int> c8({ 1, 2, 3, 4 });
initializer_list<int> iList{ 5, 6, 7, 8 };
deque<int> c9( iList);
cout << "c1 = ";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << *c1_Iter << " ";
cout << endl;
cout << "c2 = ";
for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
cout << *c2_Iter << " ";
cout << endl;
cout << "c3 = ";
for ( c3_Iter = c3.begin( ); c3_Iter != c3.end( ); c3_Iter++ )
cout << *c3_Iter << " ";
cout << endl;
cout << "c4 = ";
for ( c4_Iter = c4.begin( ); c4_Iter != c4.end( ); c4_Iter++ )
cout << *c4_Iter << " ";
cout << endl;
cout << "c5 = ";
for ( c5_Iter = c5.begin( ); c5_Iter != c5.end( ); c5_Iter++ )
cout << *c5_Iter << " ";
cout << endl;
cout << "c6 = ";
for ( c6_Iter = c6.begin( ); c6_Iter != c6.end( ); c6_Iter++ )
cout << *c6_Iter << " ";
cout << endl;
// Move deque c6 to deque c7
deque <int> c7( move(c6) );
deque <int>::iterator c7_Iter;
cout << "c7 =" ;
for ( c7_Iter = c7.begin( ) ; c7_Iter != c7.end( ) ; c7_Iter++ )
cout << " " << *c7_Iter;
cout << endl;
cout << "c8 = ";
for (int i : c8)
cout << i << " ";
cout << endl;
cout << "c9 = ";
or (int i : c9)
cout << i << " ";
cout << endl;
}
Output
c1 = 0 0 0
c2 = 2 2 2 2 2
c3 = 1 1 1
c4 = 2 2 2 2 2
c5 = 2 2
c6 = 2 2 2
c7 = 2 2 2
c8 = 1 2 3 4
c9 = 5 6 7 8
要求
标头: <deque>
命名空间: std