std::list<T,Allocator>::splice (3) - Linux Manuals
std::list<T,Allocator>::splice: std::list<T,Allocator>::splice
Command to display std::list<T,Allocator>::splice
manual in Linux: $ man 3 std::list<T,Allocator>::splice
NAME
std::list<T,Allocator>::splice - std::list<T,Allocator>::splice
Synopsis
void splice( const_iterator pos, list& other ); (1)
void splice( const_iterator pos, list&& other ); (1) (since C++11)
void splice( const_iterator pos, list& other, const_iterator it ); (2)
void splice( const_iterator pos, list&& other, const_iterator it ); (2) (since C++11)
void splice( const_iterator pos, list& other, (3)
const_iterator first, const_iterator last);
void splice( const_iterator pos, list&& other, (3) (since C++11)
const_iterator first, const_iterator last );
Transfers elements from one list to another.
No elements are copied or moved, only the internal pointers of the list nodes are re-pointed. The behavior is undefined if: get_allocator() != other.get_allocator(). No iterators or references become invalidated, the iterators to moved elements remain valid, but now refer into *this, not into other.
1) Transfers all elements from other into *this. The elements are inserted before the element pointed to by pos. The container other becomes empty after the operation. The behavior is undefined if other refers to the same object as *this.
2) Transfers the element pointed to by it from other into *this. The element is inserted before the element pointed to by pos.
3) Transfers the elements in the range [first, last) from other into *this. The elements are inserted before the element pointed to by pos. The behavior is undefined if pos is an iterator in the range [first,last).
Parameters
pos - element before which the content will be inserted
other - another container to transfer the content from
it - the element to transfer from other to *this
first, last - the range of elements to transfer from other to *this
Return value
(none)
Exceptions
Throws nothing.
Complexity
1-2) Constant.
3) Constant if other refers to the same object as *this, otherwise linear in std::distance(first, last).
Example
// Run this code
#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";
}
Output:
list1: 1 2 10 20 30 40 50 3 4 5
list2:
list1: 1 2 10 20 30 40 50
list2: 3 4 5
See also
merges two sorted lists
merge (public member function)
removes elements satisfying specific criteria
remove (public member function)
remove_if
Pages related to std::list<T,Allocator>::splice
- std::list<T,Allocator>::size (3) - std::list<T,Allocator>::size
- std::list<T,Allocator>::sort (3) - std::list<T,Allocator>::sort
- std::list<T,Allocator>::swap (3) - std::list<T,Allocator>::swap
- std::list<T,Allocator>::assign (3) - std::list<T,Allocator>::assign
- std::list<T,Allocator>::back (3) - std::list<T,Allocator>::back
- std::list<T,Allocator>::begin,std::list<T,Allocator>::cbegin (3) - std::list<T,Allocator>::begin,std::list<T,Allocator>::cbegin
- std::list<T,Allocator>::clear (3) - std::list<T,Allocator>::clear
- std::list<T,Allocator>::emplace (3) - std::list<T,Allocator>::emplace
- std::list<T,Allocator>::emplace_back (3) - std::list<T,Allocator>::emplace_back
- std::list<T,Allocator>::emplace_front (3) - std::list<T,Allocator>::emplace_front
- std::list<T,Allocator>::empty (3) - std::list<T,Allocator>::empty
- std::list<T,Allocator>::end,std::list<T,Allocator>::cend (3) - std::list<T,Allocator>::end,std::list<T,Allocator>::cend
- std::list<T,Allocator>::erase (3) - std::list<T,Allocator>::erase
- std::list<T,Allocator>::front (3) - std::list<T,Allocator>::front
- std::list<T,Allocator>::get_allocator (3) - std::list<T,Allocator>::get_allocator
- std::list<T,Allocator>::insert (3) - std::list<T,Allocator>::insert
- std::list<T,Allocator>::list (3) - std::list<T,Allocator>::list
- std::list<T,Allocator>::max_size (3) - std::list<T,Allocator>::max_size
- std::list<T,Allocator>::merge (3) - std::list<T,Allocator>::merge
- std::list<T,Allocator>::operator= (3) - std::list<T,Allocator>::operator=
- std::list<T,Allocator>::pop_back (3) - std::list<T,Allocator>::pop_back
- std::list<T,Allocator>::pop_front (3) - std::list<T,Allocator>::pop_front
- std::list<T,Allocator>::push_back (3) - std::list<T,Allocator>::push_back
- std::list<T,Allocator>::push_front (3) - std::list<T,Allocator>::push_front
- std::list<T,Allocator>::rbegin,std::list<T,Allocator>::crbegin (3) - std::list<T,Allocator>::rbegin,std::list<T,Allocator>::crbegin
- std::list<T,Allocator>::remove,remove_if (3) - std::list<T,Allocator>::remove,remove_if
- std::list<T,Allocator>::rend,std::list<T,Allocator>::crend (3) - std::list<T,Allocator>::rend,std::list<T,Allocator>::crend
- std::list<T,Allocator>::resize (3) - std::list<T,Allocator>::resize