std::list<T,Allocator>:: splice
|
void
splice
(
const_iterator pos, list
&
other
)
;
|
(1) | (constexpr начиная с C++26) |
|
void
splice
(
const_iterator pos, list
&&
other
)
;
|
(2) |
(начиная с C++11)
(constexpr начиная с C++26) |
|
void
splice
(
const_iterator pos, list
&
other, const_iterator it
)
;
|
(3) | (constexpr начиная с C++26) |
|
void
splice
(
const_iterator pos, list
&&
other, const_iterator it
)
;
|
(4) |
(начиная с C++11)
(constexpr начиная с C++26) |
|
void
splice
(
const_iterator pos, list
&
other,
const_iterator first, const_iterator last ) ; |
(5) | (constexpr начиная с C++26) |
|
void
splice
(
const_iterator pos, list
&&
other,
const_iterator first, const_iterator last ) ; |
(6) |
(начиная с C++11)
(constexpr начиная с C++26) |
Перемещает элементы из other в * this . Элементы вставляются в позицию pos .
Если выполняется любое из следующих условий, поведение не определено:
-
pos
не находится в диапазоне
[begin ( ),end ( )). - get_allocator ( ) == other. get_allocator ( ) равно false .
[
begin
(
)
,
end
(
)
)
, поведение не определено.
[
first
,
last
)
.
-
[first,last)не является допустимым диапазоном в other , -
Любой итератор в
[first,last)не является разыменуемым. -
pos
находится в
[first,last).
Никакие итераторы или ссылки не становятся недействительными. Если * this и other ссылаются на разные объекты, итераторы перемещённых элементов теперь ссылаются на * this , а не на other .
Содержание |
Параметры
| pos | - | элемент, перед которым будет вставлено содержимое |
| other | - | другой контейнер, из которого переносится содержимое |
| it | - | элемент для переноса из other в * this |
| first, last | - | пара итераторов, определяющая диапазон элементов для переноса из other в * this |
Сложность
Пример
#include <iostream> #include <list> std::ostream& operator<<(std::ostream& ostr, const std::list<int>& list) { for (auto& i : list) ostr << ' ' << i; return ostr; } int main () { std::list<int> list1{1, 2, 3, 4, 5}; std::list<int> list2{10, 20, 30, 40, 50}; auto it = list1.begin(); std::advance(it, 2); list1.splice(it, list2); std::cout << "list1:" << list1 << '\n'; std::cout << "list2:" << list2 << '\n'; list2.splice(list2.begin(), list1, it, list1.end()); std::cout << "list1:" << list1 << '\n'; std::cout << "list2:" << list2 << '\n'; }
Вывод:
list1: 1 2 10 20 30 40 50 3 4 5 list2: list1: 1 2 10 20 30 40 50 list2: 3 4 5
Отчеты о дефектах
Следующие отчеты об изменениях поведения, влияющие на дефекты, были применены ретроактивно к ранее опубликованным стандартам C++.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 250 | C++98 |
references and iterators to the moved
element(s) were all invalidated |
they refer or point to the
same element(s) in * this |
| N2525 | C++98 |
O(1) splicing could not be guaranteed if
get_allocator ( ) ! = other. get_allocator ( ) |
the behavior is
undefined in this case |
Смотрите также
|
объединяет два отсортированных списка
(публичная функция-член) |
|
|
удаляет элементы, удовлетворяющие определенным критериям
(публичная функция-член) |