namespace std {
template <class T, class Allocator, class U = T>
typename hive<T, Allocator>::size_type
erase(hive<T, Allocator>& c, const U& value); // (1) C++26
}
概要
指定した値をもつ要素とその分の領域を、コンテナから削除する。
効果
以下と等価である:
return erase_if(c, [&](const auto& elem) -> bool { return elem == value; });
戻り値
削除した要素数を返す。
例
#include <hive>
#include <print>
int main()
{
std::hive<int> h = {3, 1, 4, 1, 5};
// コンテナhから、値1をもつ要素をすべて削除する
std::hive<int>::size_type n = std::erase(h, 1);
std::println("erased = {}", n);
for (int x : h) {
std::print("{} ", x);
}
std::println("");
}
出力
erased = 2
3 4 5
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌
関連項目
参照
- P0447R28 Introduction of
std::hiveto the standard library- C++26で
hiveが追加された
- C++26で
- LWG Issue 4233. The helper lambda of
std::eraseforhiveshould specify return type asbool- C++26で、テンプレートパラメータ
Uにデフォルト引数= Tが追加され、効果のラムダに戻り値型-> boolが明示された
- C++26で、テンプレートパラメータ