static constexpr void reserve(size_type n); // (1) C++26
概要
容量を確認する。inplace_vectorの容量は固定であるため、この関数は容量の変更を行わない。nがN以下であれば何もせず、nがNを超える場合は例外を送出する。
この関数は、std::vector::reserve()との互換性のために提供されている。
例外
n > Nの場合、std::bad_alloc例外を送出する。
戻り値
なし
計算量
定数時間
例
#include <print>
#include <inplace_vector>
#include <stdexcept>
int main()
{
std::inplace_vector<int, 5> iv;
// 容量内なので何も起きない
iv.reserve(3);
std::println("reserve(3): OK");
// 容量超過で例外
try {
iv.reserve(10);
}
catch (const std::bad_alloc&) {
std::println("reserve(10): bad_alloc");
}
}
出力
reserve(3): OK
reserve(10): bad_alloc
バージョン
言語
- C++26
処理系
- Clang: 23 ✅
- GCC: 16 ✅
- Visual C++: 2026 Update 2 ❌