constexpr auto size()
requires sized_range<V>; // (1) C++23
constexpr auto size() const
requires sized_range<const V>; // (2) C++23
概要
要素数を取得する。
戻り値
メンバ変数base_
として保持しているRangeへのポインタがあるとして、以下を返す:
return ranges::size(base_);
例
#include <iostream>
#include <vector>
#include <ranges>
int main() {
std::vector<int> v = {1, 2, 3};
auto r = std::ranges::as_rvalue_view(v);
std::cout << r.size() << std::endl;
}
出力
3
バージョン
言語
- C++23
処理系
- Clang: 17 ✅
- GCC: 13 ✅
- ICC: ?
- Visual C++: 2022 Update 4 ✅