template <class... Args>
iterator emplace_after(const_iterator position, Args&&... args);
概要
任意の位置に直接構築で要素を挿入する。
この関数の引数args...
は、要素型T
のコンストラクタ引数である。当関数の内部で要素型T
のコンストラクタを呼び出し、追加する要素を構築する。
第1パラメータposition
で指定された要素の後ろに追加する。
要件
第1パラメータposition
が、before_begin()
もしくはイテレータ範囲[begin(), end())
の間接参照可能なイテレータであること。
戻り値
挿入された要素を指すイテレータ
計算量
定数時間
例
#include <iostream>
#include <forward_list>
#include <iterator>
#include <utility>
#include <string>
#include <algorithm>
int main()
{
std::forward_list<std::pair<int, std::string>> ls = {
{1, "a"},
{2, "b"},
{4, "d"}
};
ls.emplace_after(std::next(ls.begin(), 1), 3, "c");
std::for_each(ls.begin(), ls.end(), [](decltype(ls)::const_reference x) {
std::cout << x.first << ',' << x.second << std::endl;
});
}
出力
1,a
2,b
3,c
4,d
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 4.7.0
- ICC: ??
- Visual C++: 2010, 2012, 2013, 2015, 2017
- 2010は、可変引数テンプレートに対応していないため、
args
に1つしか実引数を渡せない。 - 2012は、可変引数テンプレートに対応していないため、不完全な実装である。
- 2010は、可変引数テンプレートに対応していないため、