constexpr auto size()
requires sized_range<V>; // (1) C++23
constexpr auto size() const
requires sized_range<const V>; // (2) C++23
概要
要素数を取得する。
効果
- (1) :
return ranges::size(base_);
- (2) :
return ranges::size(base_);
例
#include <ranges>
#include <vector>
#include <iostream>
int main() {
std::vector<char> v = {'a', 'b', 'c'};
std::ranges::enumerate_view ev(v);
// サイズを取得
std::cout << "size: " << ev.size() << std::endl;
// const版も動作する
const auto& cev = ev;
std::cout << "const size: " << cev.size() << std::endl;
}
出力
size: 3
const size: 3
バージョン
言語
- C++23
処理系
- Clang: 17 ✅
- GCC: 13 ✅
- Visual C++: 2022 Update 7 ✅