std::list<T,Allocator>:: list
|
list
(
)
:
list
(
Allocator
(
)
)
{
}
|
(1) |
(начиная с C++11)
(constexpr начиная с C++26) |
| (2) | ||
|
explicit
list
(
const
Allocator
&
alloc
=
Allocator
(
)
)
;
|
(до C++11) | |
|
explicit
list
(
const
Allocator
&
alloc
)
;
|
(начиная с C++11)
(constexpr начиная с C++26) |
|
|
explicit
list
(
size_type count,
const Allocator & alloc = Allocator ( ) ) ; |
(3) |
(начиная с C++11)
(constexpr начиная с C++26) |
| (4) | ||
|
explicit
list
(
size_type count,
const
T
&
value
=
T
(
)
,
const Allocator & alloc = Allocator ( ) ) ; |
(до C++11) | |
|
list
(
size_type count,
const
T
&
value,
const Allocator & alloc = Allocator ( ) ) ; |
(начиная с C++11)
(constexpr начиная с C++26) |
|
|
template
<
class
InputIt
>
list
(
InputIt first, InputIt last,
|
(5) | (constexpr начиная с C++26) |
|
template
<
container-compatible-range
<
T
>
R
>
list
(
std::
from_range_t
, R
&&
rg,
|
(6) |
(начиная с C++23)
(constexpr начиная с C++26) |
|
list
(
const
list
&
other
)
;
|
(7) | (constexpr начиная с C++26) |
|
list
(
list
&&
other
)
;
|
(8) |
(начиная с C++11)
(constexpr начиная с C++26) |
| (9) | ||
|
list
(
const
list
&
other,
const
Allocator
&
alloc
)
;
|
(начиная с C++11)
(до C++23) |
|
|
list
(
const
list
&
other,
const std:: type_identity_t < Allocator > & alloc ) ; |
(начиная с C++23)
(constexpr начиная с C++26) |
|
| (10) | ||
|
list
(
list
&&
other,
const
Allocator
&
alloc
)
;
|
(начиная с C++11)
(до C++23) |
|
|
list
(
list
&&
other,
const
std::
type_identity_t
<
Allocator
>
&
alloc
)
;
|
(начиная с C++23)
(constexpr начиная с C++26) |
|
|
list
(
std::
initializer_list
<
T
>
init,
const Allocator & alloc = Allocator ( ) ) ; |
(11) |
(начиная с C++11)
(constexpr начиная с C++26) |
Создает новый
list
из различных источников данных, опционально используя предоставленный пользователем аллокатор
alloc
.
list
с аллокатором, созданным по умолчанию.
list
с заданным аллокатором
alloc
.
list
с
count
объектами типа
T
, вставленными по умолчанию. Копирования не выполняются.
list
с
count
копиями элементов со значением
value
.
|
Если
|
(since C++11) |
list
с содержимым диапазона
[
first
,
last
)
. Каждый итератор в
[
first
,
last
)
разыменовывается ровно один раз.
|
Если
|
(до C++11) |
|
Эта перегрузка участвует в разрешении перегрузки только если
Если
|
(начиная с C++11) |
list
с содержимым диапазона
rg
. Каждый итератор в
rg
разыменовывается ровно один раз.
T
не является
EmplaceConstructible
в
list
из
*
ranges::
begin
(
rg
)
, поведение не определено.
list
с содержимым
other
.
|
Аллокатор получается как если бы вызывался
std::
allocator_traits
<
Allocator
>
::
select_on_container_copy_construction
|
(since C++11) |
list
с содержимым
other
. Аллокатор получается путем перемещения из
other.
get_allocator
(
)
.
СодержаниеПараметры
Сложность
1,2)
Константа.
3,4)
Линейно по
count
.
5)
Линейная по
std::
distance
(
first, last
)
.
6)
Линейная по
ranges::
distance
(
rg
)
.
7)
Линейно от
other.
size
(
)
.
8)
Константа.
9)
Линейно от
other.
size
(
)
.
10)
Линейная по
other.
size
(
)
если
alloc
!
=
other.
get_allocator
(
)
, иначе константная.
11)
Линейная от
init.
size
(
)
.
ИсключенияВызовы Allocator :: allocate могут генерировать исключения. ПримечанияПосле перемещения контейнера (перегрузка (8)), ссылки, указатели и итераторы, которые изначально ссылались на элементы в
Пример
Запустить этот код
#include <iostream> #include <list> #include <string> template<typename T> std::ostream& operator<<(std::ostream& s, const std::list<T>& v) { s.put('{'); for (char comma[]{'\0', ' ', '\0'}; const auto& e : v) s << comma << e, comma[0] = ','; return s << "}\n"; } int main() { // Синтаксис списка инициализации C++11: std::list<std::string> words1{"the", "frogurt", "is", "also", "cursed"}; std::cout << "1: " << words1; // words2 == words1 std::list<std::string> words2(words1.begin(), words1.end()); std::cout << "2: " << words2; // words3 == words1 std::list<std::string> words3(words1); std::cout << "3: " << words3; // words4 это {"Mo", "Mo", "Mo", "Mo", "Mo"} std::list<std::string> words4(5, "Mo"); std::cout << "4: " << words4; const auto rg = {"cat", "cow", "crow"}; #ifdef __cpp_lib_containers_ranges std::list<std::string> words5(std::from_range, rg); // перегрузка (6) #else std::list<std::string> words5(rg.begin(), rg.end()); // перегрузка (5) #endif std::cout << "5: " << words5; } Вывод: 1: {the, frogurt, is, also, cursed}
2: {the, frogurt, is, also, cursed}
3: {the, frogurt, is, also, cursed}
4: {Mo, Mo, Mo, Mo, Mo}
5: {cat, cow, crow}
Отчёты о дефектахСледующие отчеты об изменениях в поведении, содержащие описания дефектов, были применены ретроактивно к ранее опубликованным стандартам C++.
Смотрите также
|