std::inplace_vector<T,N>::reserve
From cppreference.com
< cpp | container | inplace vector
| static constexpr void reserve( size_type new_cap ); |
(C++26以降) | |
何もしません。ただし、std::bad_alloc をスローする可能性はあります。容量の増加要求(すなわち、内部ストレージサイズ)は無視されます。これは、std::inplace_vector<T, N> が固定容量コンテナであるためです。
目次 |
[編集] パラメータ
| new_cap | - | inplace_vector の新しい容量(要素数) |
[編集] 戻り値
(なし)
[編集] 計算量
定数。
[編集] 例外
std::bad_alloc new_cap > capacity() が true の場合。
[編集] 注記
この関数は、vector のようなインターフェースとの互換性のために存在します。
[編集] 例
このコードを実行
#include <cassert> #include <inplace_vector> #include <iostream> int main() { std::inplace_vector<int, 4> v{1, 2, 3}; assert(v.capacity() == 4 && v.size() == 3); v.reserve(2); // does nothing assert(v.capacity() == 4 && v.size() == 3); try { v.reserve(13); // throws, because requested capacity > N; v is left unchanged } catch(const std::bad_alloc& ex) { std::cout << ex.what() << '\n'; } assert(v.capacity() == 4 && v.size() == 3); }
実行結果の例
std::bad_alloc
[編集] 関連項目
| 要素数を返す (public メンバ関数) | |
| [static] |
可能な最大要素数を返す (public static member function) |
| 格納されている要素の数を変更する (公開メンバ関数) | |
| [static] |
現在確保されているストレージに保持できる要素数を返す (public static member function) |
| [static] |
未使用のメモリを解放してメモリ使用量を削減する (public static member function) |