constexpr auto reserve_hint()
requires approximately_sized_range<V>; // (1) C++26
constexpr auto reserve_hint() const
requires approximately_sized_range<const V>; // (2) C++26
概要
要素数の近似値を取得する。
adjacent_viewは元のRangeから N 個の連続する要素のタプルを生成するため、要素数の近似値は「元のRangeのreserve_hint − N + 1」(負になる場合は 0)となる。
テンプレートパラメータ制約
- (1) : 型
Vがapproximately_sized_rangeであること - (2) : 型
const Vがapproximately_sized_rangeであること
効果
以下と等価:
using DT = range_difference_t<decltype((base_))>;
using CT = common_type_t<DT, size_t>;
auto sz = static_cast<CT>(ranges::reserve_hint(base_));
sz -= std::min<CT>(sz, N - 1);
return to-unsigned-like(sz);
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌