Почему?
Я полагаю, причина в том, что iota_view Foo не знает, как продвигать Foo. Но как мне об этом узнать?
Код: Выделить всё
#include
#include
struct Foo {
int x;
Foo() : x{-1} {}
Foo(int x) : x{x} {}
using difference_type = int;
friend auto operator(Foo const& a, Foo const& b) {
return a.x b.x;
}
friend bool operator==(Foo const& a, Foo const& b) {
return a.x == b.x;
}
auto& operator++() {
++x;
return *this;
}
auto operator++(int) {
auto r = *this;
++x;
return r;
}
};
int main () {
auto ints = std::views::iota(1, 30);
for (auto i : ints) {}
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/76167127/why-does-the-random-access-property-of-iota-view-depend-on-the-element-type-and[/url]
Мобильная версия