std::ranges::adjacent_view<V,N>::size
來自 cppreference.com
< cpp | ranges | adjacent view
constexpr auto size() requires ranges::sized_range<V>; |
(C++23 起) | |
constexpr auto size() const requires ranges::sized_range<const V>; |
(C++23 起) | |
返回元素數量。
令 base_
為底層檢視。等價於:
using SizeType = decltype(ranges::size(base_)); using CommonType = ranges::common_type_t<SizeType, std::size_t>; auto size = static_cast<CommonType>(ranges::size(base_)); size -= std::min<CommonType>(size, N - 1); return static_cast<SizeType>(size);
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
元素數量,如果 ranges::size(base_) 小於 N 則可能為 0 。
[編輯] 示例
執行此程式碼
#include <ranges> int main() { constexpr static auto v = {1, 2, 3, 4, 5, 6}; constexpr int width1 {4}; constexpr auto view1 {std::views::adjacent<width1>(v)}; static_assert(view1.size() == 3); static_assert(view1.size() == (v.size() - width1 + 1)); constexpr int width2 {8}; constexpr auto view2 {std::views::adjacent<width2>(v)}; // window is too wide, so view2 has no elements: static_assert(view2.size() == 0); }
[編輯] 參閱
(C++20) |
返回等於範圍大小的整數 (自定義點物件) |
(C++20) |
返回等於範圍大小的有符號整數 (自定義點物件) |