- ranges[meta header]
- std::ranges[meta namespace]
- subrange[meta class]
- function[meta id-type]
- cpp20[meta cpp]
constexpr make-unsigned-like-t<iter_difference_t<I>> size() const
requires (K == subrange_kind::sized);
- make-unsigned-like-t[italic][link /reference/type_traits/make_unsigned.md]
- iter_difference_t[link /reference/iterator/iter_difference_t.md]
- subrange_kind[link /reference/ranges/subrange_kind.md]
subrange
の大きさを取得する。
この関数は、subrange
がsized
のときのみオーバーロード解決に参加する。
StoreSize
が真のとき、return size_;
- それ以外のとき、
return
to-unsigned-like
(end_ - begin_);
#include <ranges>
#include <iostream>
int main()
{
constexpr int a[] = {1, 2, 3};
const std::ranges::subrange sub1(a);
const std::ranges::subrange sub2(a, a);
std::cout << sub1.size() << '\n';
std::cout << sub2.size() << '\n';
}
3
0
- C++20
- Clang: 13.0.0 [mark verified]
- GCC: 10.1.0 [mark verified]
- ICC: ?
- Visual C++: 2019 Update 10 [mark verified]