GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::forward_list::emplace_after(3) C++ Standard Libary std::forward_list::emplace_after(3)

std::forward_list::emplace_after - std::forward_list::emplace_after


template< class... Args > (since C++11)
iterator emplace_after( const_iterator pos, Args&&... args );


Inserts a new element into a position after the specified position in the container.
The element is constructed in-place, i.e. no copy or move operations are performed.
The constructor of the element is called with exactly the same arguments, as
supplied to the function.


No iterators or references are invalidated.


pos - iterator after which the new element will be constructed
args - arguments to forward to the constructor of the element


iterator to the new element.


Constant.


If an exception is thrown (e.g. by the constructor), the container is left
unmodified, as if this function was never called (strong exception guarantee).


The example demonstrates a canonical filling of a single-linked list in natural (as
opposed to reverse) order.

// Run this code


#include <forward_list>
#include <iostream>
#include <string>


struct Sum {
std::string remark;
int sum;


Sum(std::string remark, int sum)
: remark{std::move(remark)}, sum{sum} {}


void print() const {
std::cout << remark << " = " << sum << '\n';
}
};


int main()
{
std::forward_list<Sum> list;


auto iter = list.before_begin();
std::string str{"1"};
for (int i{1}, sum{1}; i != 10; sum += i) {
iter = list.emplace_after(iter, str, sum);
++i;
str += " + " + std::to_string(i);
}


for (const Sum& s : list) s.print();
}


1 = 1
1 + 2 = 3
1 + 2 + 3 = 6
1 + 2 + 3 + 4 = 10
1 + 2 + 3 + 4 + 5 = 15
1 + 2 + 3 + 4 + 5 + 6 = 21
1 + 2 + 3 + 4 + 5 + 6 + 7 = 28
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45


insert_after inserts elements after an element
(C++11) (public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.