名稱空間
變體
操作

std::ranges::iota_view 的推導指南

來自 cppreference.com
< cpp‎ | ranges‎ | iota view
 
 
範圍庫 (Ranges library)
範圍介面卡 (Range adaptors)
 
 
定義於標頭檔案 <ranges>
template< class W, class Bound >

    requires (!/*is-integer-like*/<W> ||
              !/*is-integer-like*/<Bound> ||
              /*is-signed-integer-like*/<W> == /*is-signed-integer-like*/<Bound>)

iota_view( W, Bound ) -> iota_view<W, Bound>;
(C++20 起)

推導指南iota_view提供,允許從初始值和邊界值進行推導。

關於/*is-integer-like*//*is-signed-integer-like*/的定義,請參閱is-integer-like 。

請注意,此指南透過防止符號不匹配引起的錯誤來保護自身,例如views::iota(0, v.size()),其中0是帶符號的,而v.size()是無符號的。

[編輯] 示例

#include <cassert>
#include <ranges>
 
int main()
{
    auto io = std::ranges::iota_view(1L, 7L); // deduces W and Bound as “long”
    assert(io.front() == 1L and io.back() == 6L);
}