首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::list::list

(1)

explicit list( const Allocator& alloc = Allocator() );

(until C++14)

list() : list( Allocator() ) {} explicit list( const Allocator& alloc );

(since C++14)

(2)

explicit list( size_type count, const T& value = T(), const Allocator& alloc = Allocator());

(until C++11)

list( size_type count, const T& value, const Allocator& alloc = Allocator());

(since C++11)

(3)

explicit list( size_type count );

(since C++11) (until C++14)

explicit list( size_type count, const Allocator& alloc = Allocator() );

(since C++14)

template< class InputIt > list( InputIt first, InputIt last, const Allocator& alloc = Allocator() );

(4)

list( const list& other );

(5)

list( const list& other, const Allocator& alloc );

(5)

(since C++11)

list( list&& other );

(6)

(since C++11)

list( list&& other, const Allocator& alloc );

(7)

(since C++11)

list( std::initializer_list<T> init, const Allocator& alloc = Allocator() );

(8)

(since C++11)

从各种数据源构造一个新容器,可以选择使用用户提供的分配器。alloc...

1%29默认构造函数。构造空容器。

2%29用count具有价值的元素的副本value...

3%29用count默认插入实例T.不制作副本。

4%29构造包含范围内容的容器。[first, last)...

This constructor has the same effect as list(static_cast<size_type>(first), static_cast<value_type>(last), a) if InputIt is an integral type.

(until C++11)

This overload only participates in overload resolution if InputIt satisfies InputIterator, to avoid ambiguity with the overload (2).

(since C++11)

5%29复制构造函数。的内容的副本构造容器。other.如果alloc如果不提供分配器,则获得分配器时,就像通过调用std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.get_allocator())...

6%29移动构造函数。的内容构造容器。other使用移动语义。分配器是通过移动构造从分配器获得的,该分配器属于other...

7%29分配器-扩展移动构造函数。使用alloc作为新容器的分配器,将内容从other;如果alloc != other.get_allocator(),这就导致了一个元素上的移动。

8%29使用初始化程序列表的内容构造容器。init...

参数

alloc

-

allocator to use for all memory allocations of this container

count

-

the size of the container

value

-

the value to initialize elements of the container with

first, last

-

the range to copy the elements from

other

-

another container to be used as source to initialize the elements of the container with

init

-

initializer list to initialize the elements of the container with

复杂性

1%29常数

2-3%29线性count

4%29直线距离firstlast

5%29线性other

6%29常数。

7%29线性IFalloc != other.get_allocator(),否则不变。

8%29线性init...

注记

在容器移动构造%28重载%286%29%29之后,引用、指针和迭代器%28---other保持有效,但引用当前在*this.现行标准通过第23.2.1节中的总括声明作出这一保证。集装箱。所需经费/12,目前正在考虑通过以下方式提供更直接的担保:lwg 2321...

二次

代码语言:javascript
复制
#include <list>
#include <string>
#include <iostream>
 
template<typename T>
std::ostream& operator<<(std::ostream& s, const std::list<T>& v) {
    s.put('[');
    char comma[3] = {'\0', ' ', '\0'};
    for (const auto& e : v) {
        s << comma << e;
        comma[0] = ',';
    }
    return s << ']';
}
 
int main() 
{
    // c++11 initializer list syntax:
    std::list<std::string> words1 {"the", "frogurt", "is", "also", "cursed"};
    std::cout << "words1: " << words1 << '\n';
 
    // words2 == words1
    std::list<std::string> words2(words1.begin(), words1.end());
    std::cout << "words2: " << words2 << '\n';
 
    // words3 == words1
    std::list<std::string> words3(words1);
    std::cout << "words3: " << words3 << '\n';
 
    // words4 is {"Mo", "Mo", "Mo", "Mo", "Mo"}
    std::list<std::string> words4(5, "Mo");
    std::cout << "words4: " << words4 << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
words1: [the, frogurt, is, also, cursed]
words2: [the, frogurt, is, also, cursed]
words3: [the, frogurt, is, also, cursed]
words4: [Mo, Mo, Mo, Mo, Mo]

二次

另见

assign

assigns values to the container (public member function)

operator=

assigns values to the container (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券