std::forward_list<T,Allocator>::splice_after (3) - Linux Manuals
std::forward_list<T,Allocator>::splice_after: std::forward_list<T,Allocator>::splice_after
Command to display std::forward_list<T,Allocator>::splice_after
manual in Linux: $ man 3 std::forward_list<T,Allocator>::splice_after
NAME
std::forward_list<T,Allocator>::splice_after - std::forward_list<T,Allocator>::splice_after
Synopsis
void splice_after( const_iterator pos, forward_list& other ); (1) (since C++11)
void splice_after( const_iterator pos, forward_list&& other ); (1) (since C++11)
void splice_after( const_iterator pos, forward_list& other, (2) (since C++11)
const_iterator it );
void splice_after( const_iterator pos, forward_list&& other, (2) (since C++11)
const_iterator it );
void splice_after( const_iterator pos, forward_list& other, (3) (since C++11)
const_iterator first, const_iterator last );
void splice_after( const_iterator pos, forward_list&& other, (3) (since C++11)
const_iterator first, const_iterator last );
Moves elements from another forward_list to *this.
No elements are copied. pos must be either a deferenceable valid iterator into *this or the before_begin() iterator (in particular, end() is not a valid argument for pos). The behavior is undefined if get_allocator() != other.get_allocator(). No iterators or references become invalidated, the iterators to the moved elements now refer into *this, not into other.
1) Moves all elements from other into *this. The elements are inserted after 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) Moves the element pointed to by the iterator following it from other into *this. The element is inserted after the element pointed to by pos. Has no effect if pos==it or if pos==++it.
3) Moves the elements in the range (first, last) from other into *this. The elements are inserted after the element pointed to by pos. The element pointed-to by first is not moved. The behavior is undefined if pos is an iterator in the range (first,last).
Parameters
pos - element after which the content will be inserted
other - another container to move the content from
it - iterator preceding the iterator to the element to move from other to *this
first, last - the range of elements to move from other to *this
Return value
(none)
Exceptions
Throws nothing.
Complexity
1) Linear in the size of other
2) Constant
3) Linear in std::distance(first, last)
Example
Demonstrates the meaning of open interval (first, last) in the third form of splice_after(): the first element of l1 is not moved.
// Run this code
#include <iostream>
#include <forward_list>
int main()
{
std::forward_list<int> l1 = {1,2,3,4,5};
std::forward_list<int> l2 = {10,11,12};
l2.splice_after(l2.cbegin(), l1, l1.cbegin(), l1.cend());
// not equivalent to l2.splice_after(l2.cbegin(), l1);
for(int n : l1)
std::cout << n << ' ';
std::cout << '\n';
for(int n : l2)
std::cout << n << ' ';
std::cout << '\n';
}
Output:
1
10 2 3 4 5 11 12
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::forward_list<T,Allocator>::splice_after
- std::forward_list<T,Allocator>::sort (3) - std::forward_list<T,Allocator>::sort
- std::forward_list<T,Allocator>::swap (3) - std::forward_list<T,Allocator>::swap
- std::forward_list<T,Allocator>::assign (3) - std::forward_list<T,Allocator>::assign
- std::forward_list<T,Allocator>::before_begin,cbefore_begin (3) - std::forward_list<T,Allocator>::before_begin,cbefore_begin
- std::forward_list<T,Allocator>::begin,std::forward_list<T,Allocator>::cbegin (3) - std::forward_list<T,Allocator>::begin,std::forward_list<T,Allocator>::cbegin
- std::forward_list<T,Allocator>::clear (3) - std::forward_list<T,Allocator>::clear
- std::forward_list<T,Allocator>::emplace_after (3) - std::forward_list<T,Allocator>::emplace_after
- std::forward_list<T,Allocator>::emplace_front (3) - std::forward_list<T,Allocator>::emplace_front
- std::forward_list<T,Allocator>::empty (3) - std::forward_list<T,Allocator>::empty
- std::forward_list<T,Allocator>::end,std::forward_list<T,Allocator>::cend (3) - std::forward_list<T,Allocator>::end,std::forward_list<T,Allocator>::cend
- std::forward_list<T,Allocator>::erase_after (3) - std::forward_list<T,Allocator>::erase_after
- std::forward_list<T,Allocator>::forward_list (3) - std::forward_list<T,Allocator>::forward_list
- std::forward_list<T,Allocator>::front (3) - std::forward_list<T,Allocator>::front
- std::forward_list<T,Allocator>::get_allocator (3) - std::forward_list<T,Allocator>::get_allocator
- std::forward_list<T,Allocator>::insert_after (3) - std::forward_list<T,Allocator>::insert_after
- std::forward_list<T,Allocator>::max_size (3) - std::forward_list<T,Allocator>::max_size
- std::forward_list<T,Allocator>::merge (3) - std::forward_list<T,Allocator>::merge
- std::forward_list<T,Allocator>::operator= (3) - std::forward_list<T,Allocator>::operator=
- std::forward_list<T,Allocator>::pop_front (3) - std::forward_list<T,Allocator>::pop_front
- std::forward_list<T,Allocator>::push_front (3) - std::forward_list<T,Allocator>::push_front
- std::forward_list<T,Allocator>::remove,remove_if (3) - std::forward_list<T,Allocator>::remove,remove_if
- std::forward_list<T,Allocator>::resize (3) - std::forward_list<T,Allocator>::resize
- std::forward_list<T,Allocator>::reverse (3) - std::forward_list<T,Allocator>::reverse
- std::forward_list<T,Allocator>::unique (3) - std::forward_list<T,Allocator>::unique
- std::forward_list<T,Allocator>::~forward_list (3) - std::forward_list<T,Allocator>::~forward_list
- std::forward_list (3) - std::forward_list