std::ranges::stride_view<V>::size
來自 cppreference.com
< cpp | ranges | stride view
constexpr auto size() requires ranges::sized_range<V>; |
(C++23 起) | |
constexpr auto size() const requires ranges::sized_range<const V>; |
(C++23 起) | |
返回元素數量。
令 base_
為底層檢視,stride_
為所儲存的步長值。等價於
return /*to-unsigned-like*/(/*div-ceil*/(ranges::distance(base_), stride_));
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
元素數量。所返回的值如同透過表示式所計算:
(ranges::size(base_) / stride_) + ((ranges::size(base_) % stride_ ? 1 : 0).
[編輯] 示例
執行此程式碼
#include <forward_list> #include <ranges> int main() { namespace vs = std::views; constexpr static auto v = {1, 2, 3, 4, 5}; static_assert ( vs::stride(v, 1).size() == 5 and vs::stride(v, 2).size() == 3 and vs::stride(v, 3).size() == 2 and vs::stride(v, 4).size() == 2 and vs::stride(v, 5).size() == 1 and vs::stride(v, 6).size() == 1 ); std::forward_list list{v}; // auto s = vs::stride(list, 2).size(); // Error: not a sized_range }
[編輯] 參閱
(C++20) |
返回等於範圍大小的整數 (定製點物件) |
(C++20) |
返回等於範圍大小的有符號整數 (定製點物件) |