template <class... Args>
iterator emplace(Args&&... args);
概要
コンテナに新しい要素を挿入する。要素は直接構築される(コピーもムーブもされない)。要素のコンストラクタはこの関数に渡された引数を与えることによって呼ばれる。
パラメータ
args...
: 要素のコンストラクタへ転送される引数パック。
テンプレートパラメータ制約
is_constructible_v<value_type, Arg...>
がtrue
であること。
戻り値
挿入された要素へのイテレータを返す。
例
単純な挿入の例
#include <flat_set>
#include <iostream>
int main()
{
std::flat_multiset<int> fs;
fs.emplace(3);
fs.emplace(1);
fs.emplace(4);
fs.emplace(1);
for (int i : fs) {
std::cout << i << std::endl;
}
}
xxxxxxxxxx
#include <flat_set>
#include <iostream>
int main()
{
std::flat_multiset<int> fs;
fs.emplace(3);
fs.emplace(1);
fs.emplace(4);
fs.emplace(1);
for (int i : fs) {
std::cout << i << std::endl;
}
}
出力
1
1
3
4
コンストラクタ引数を渡す例
#include <flat_set>
#include <iostream>
#include <iterator>
#include <string>
int main()
{
std::flat_multiset<std::string> fs;
const char aaa[3] = {'A', 'A', 'A'};
fs.emplace(5, 'C');
fs.emplace(aaa, 3);
fs.emplace("BBBB");
fs.emplace(std::begin(aaa), std::end(aaa));
for (const std::string& i : fs) {
std::cout << i << std::endl;
}
}
xxxxxxxxxx
#include <flat_set>
#include <iostream>
#include <iterator>
#include <string>
int main()
{
std::flat_multiset<std::string> fs;
const char aaa[3] = {'A', 'A', 'A'};
fs.emplace(5, 'C');
fs.emplace(aaa, 3);
fs.emplace("BBBB");
fs.emplace(std::begin(aaa), std::end(aaa));
for (const std::string& i : fs) {
std::cout << i << std::endl;
}
}
出力
AAA
AAA
BBBB
CCCCC
バージョン
言語
- C++23
処理系
- Clang: ??
- GCC: ??
- Visual C++: ??
関連項目
名前 | 説明 |
---|---|
flat_multiset::insert |
要素を挿入する |
flat_multiset::insert_range |
Rangeを挿入する |
flat_multiset::emplace_hint |
ヒントを使って要素を直接構築する |