Namespaces
Variants

deduction guides for std::ranges::iota_view

From cppreference.net
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); // 推导 W 和 Bound 为 "long" 类型
    assert(io.front() == 1L and io.back() == 6L);
}