public member function
<deque>
std::deque::deque
預設 (1) | explicit deque (const allocator_type& alloc = allocator_type()); |
---|
fill (2) | explicit deque (size_type n, const value_type& val = value_type(), 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); |
---|
預設 (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()); |
---|
預設 (1) | deque();explicit deque (const allocator_type& alloc); |
---|
fill (2) | explicit deque (size_type n, const allocator_type& alloc = allocator_type()); 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()); |
---|
Construct deque container
Constructs a deque container object, initializing its contents depending on the constructor version used
- (1) empty container constructor (default constructor)
- Constructs an empty container, with no elements.
- (2) fill constructor
- Constructs a container with n elements. Each element is a copy if val.
- (3) range constructor
- Constructs a container with as many elements as the range[first,last), with each element constructed from its corresponding element in that range, in the same order.
- (4) copy constructor
- Constructs a container with a copy of each of the elements in x, in the same order.
The container keeps an internal copy of
alloc, which is used to allocate storage throughout its lifetime. If no
alloc argument is passed to the constructor, a default-constructed allocator is used, except in the following case
- The copy constructor
(4) creates a container that keeps and uses a copy of
x's allocator.
The storage for the elements is allocated using this
internal allocator.
- (1) empty container constructor (default constructor)
- Constructs an empty container, with no elements.
- (2) fill constructor
- Constructs a container with n elements. Each element is a copy of val (if provided).
- (3) range constructor
- Constructs a container with as many elements as the range[first,last), with each element emplace-constructed from its corresponding element in that range, in the same order.
- (4) copy constructor (and copying with allocator)
- Constructs a container with a copy of each of the elements in x, in the same order.
- (5) move constructor (and moving with allocator)
- Constructs a container that acquires the elements of x.
If alloc is specified and is different from x's allocator, the elements are moved. Otherwise, no elements are constructed (their ownership is directly transferred).
x is left in an unspecified but valid state.
- (6) initializer list constructor
- Constructs a container with a copy of each of the elements in il, in the same order.
The container keeps an internal copy of
alloc, which is used to allocate and deallocate storage for its elements, and to construct and destroy them (as specified by its
allocator_traits). If no
alloc argument is passed to the constructor, a default-constructed allocator is used, except in the following cases
- The copy constructor
(4, first signature) creates a container that keeps and uses a copy of the allocator returned by calling the appropriate
selected_on_container_copy_construction trait on
x's allocator.
- The move constructor
(5, first signature) acquires
x's allocator.
All elements are
copied,
moved or otherwise
constructed by calling
allocator_traits::construct with the appropriate arguments.
引數
- alloc
- Allocator object.
The container keeps and uses an internal copy of this allocator.
成員型別allocator_typeis the internal allocator type used by the container, defined in deque as an alias of its second template parameter (Alloc).
如果已知allocator_typeis an instantiation of the default allocator (which has no state), this is not relevant.
- n
- Initial container size (i.e., the number of elements in the container at construction).
成員型別size_type是一種無符號整型型別。
- val
- Value to fill the container with. Each of the n elements in the container will be initialized to a copy of this value.
成員型別value_type是容器中元素的型別,在 deque 中定義為其第一個模板引數(T).
- first, last
- 指向範圍內初始位置和最終位置的輸入迭代器。 使用的範圍是[first,last),它包括first和last之間的所有元素,包括first指向的元素,但不包括last指向的元素。
函式模板引數InputIteratorshall be an input iterator type that points to elements of a type from whichvalue_type物件的型別的元素。
- x
- Another deque object of the same type (with the same class template argumentsT和Alloc), whose contents are either copied or acquired.
- il
- il
這些物件是從初始化列表宣告符自動構造的。
成員型別value_type是容器中元素的型別,在 deque 中定義為其第一個模板引數(T).
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
// constructing deques
#include <iostream>
#include <deque>
int main ()
{
unsigned int i;
// constructors used in the same order as described above:
std::deque<int> first; // empty deque of ints
std::deque<int> second (4,100); // four ints with value 100
std::deque<int> third (second.begin(),second.end()); // iterating through second
std::deque<int> fourth (third); // a copy of third
// the iterator constructor can be used to copy arrays:
int myints[] = {16,2,77,29};
std::deque<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
std::cout << "The contents of fifth are:";
for (std::deque<int>::iterator it = fifth.begin(); it!=fifth.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
|
輸出
The contents of fifth are: 16 2 77 29
|
複雜度
Constant for the default constructor (1), and for the move constructors (5) (unless alloc is different from x's allocator).
For all other cases, linear in the resulting container size.
迭代器有效性
The move constructors (5), invalidate all iterators, pointers and references related to x if the elements are moved.
資料競爭
All copied elements are accessed.
The move constructors (5) modify x.
異常安全
Strong guarantee: no effects in case an exception is thrown.
If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified by[first,last)無效,則會導致未定義行為。