Cherif
Cherif

Reputation: 85

Why does direct-initialization not work for std::views::iota?

Why is this an illegal declaration?

> std::views::iota r(0, 10);
error: expected ‘;’ before ‘r’

but this works

> auto r = std::views::iota(0, 10);

Upvotes: 2

Views: 78

Answers (1)

康桓瑋
康桓瑋

Reputation: 42766

views::iota is a customization point object, which is a function object that overloads an operator() that returns a ranges::iota_view object.

ranges::iota_view is the implementation details of views::iota, which is a class type. So you probably mean

std::ranges::iota_view r(0, 10);

However, you should always prefer using views::meow over ranges::meow_view.

Upvotes: 5

Related Questions