std::vector::vector
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| explicit vector( const Allocator& alloc = Allocator() ); |
(1) | |
| explicit vector( size_type count, const T& value = T(), |
(2) | (至 C++11) (C++11 起) |
| explicit vector( size_type count ); |
(3) | (C++11 起) |
| template< class InputIt > vector( InputIt first, InputIt last, |
(4) | |
| vector( const vector& other ); |
(5) | |
| vector( const vector& other, const Allocator& alloc ); |
(5) | (C++11 起) |
| vector( vector&& other ) |
(6) | (C++11 起) |
| vector( vector&& other, const Allocator& alloc ); |
(6) | (C++11 起) |
| vector( std::initializer_list<T> init, const Allocator& alloc = Allocator() ); |
(7) | (C++11 起) |
从各种数据源和构建新的容器,可以使用用户提供的分配器
alloc.Original:
Constructs new container from a variety of data sources and optionally using user supplied allocator
alloc.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
1)
默认构造函数。构造空的容器.
Original:
Default constructor. Constructs empty container.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
构造容器元素的值
countvalue副本.Original:
Constructs the container with
count copies of elements with value value.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3)
构造
count初始化的值(缺省构造,类)的实例T的容器。没有副本.Original:
Constructs the container with
count value-initialized (default constructed, for classes) instances of T. No copies are made.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
4)
构造的容器的内容的范围内
[first, last).Original:
Constructs the container with the contents of the range
[first, last).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
5)
拷贝构造函数。副本的内容
other构造的容器。 alloc不提供,分配器是通过调用std::allocator_traits<allocator_type>::select_on_copy_construction(other).Original:
Copy constructor. Constructs the container with the copy of the contents of
other. If alloc is not provided, allocator is obtained by calling std::allocator_traits<allocator_type>::select_on_copy_construction(other).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
6)
移动的构造函数。构造的容器与内容
other使用移动语义。 alloc不提供,分配器是通过移动建设属于other从分配器.Original:
Move constructor. Constructs the container with the contents of
other using move semantics. If alloc is not provided, allocator is obtained by move-construction from the allocator belonging to other.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
7)
构造容器初始化列表的内容
init Original:
Constructs the container with the contents of the initializer list
init. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| alloc | - | 使用这个容器中的所有内存分配的分配器
Original: allocator to use for all memory allocations of this container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| count | - | 的容器的大小
Original: the size of the container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| value | - | 的值初始化容器的元素
Original: the value to initialize elements of the container with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| first, last | - | 取值范围为从复制元素
Original: the range to copy the elements from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| other | - | 要用作源初始化容器的元素与另一个容器
Original: another container to be used as source to initialize the elements of the container with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| init | - | 的初始化列表初始化容器元素
Original: initializer list to initialize the elements of the container with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| Type requirements | ||
-InputIt must meet the requirements of InputIterator.
| ||
[编辑] 复杂性
1)
常数
Original:
Constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2-3)
线性
countOriginal:
Linear in
countThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
4)
first和last之间的距离呈线性关系Original:
Linear in distance between
first and lastThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
5)
线性大小
otherOriginal:
Linear in size of
otherThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
6)
常数。如果
alloc,并给出alloc != other.get_allocator(),则采用线性.Original:
Constant. If
alloc is given and alloc != other.get_allocator(), then linear.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
7)
线性大小
initOriginal:
Linear in size of
initThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
#include <vector> #include <string> int main() { // c++11 initializer list syntax: std::vector<std::string> words1 {"the", "frogurt", "is", "also", "cursed"}; // words2 == words1 std::vector<std::string> words2(words1.begin(), words1.end()); // words3 == words1 std::vector<std::string> words3(words1); // words4 is {"Mo", "Mo", "Mo", "Mo", "Mo"} std::vector<std::string> words4(5, "Mo"); return 0; }
[编辑] 另请参阅
| 将值分配到容器中 Original: assigns values to the container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 将值分配到容器中 Original: assigns values to the container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |