C++ ranges/views vs. Rust iterator

2 pointsposted 11 hours ago
by bijan7

Item id: 45253734

1 Comments

npalli

6 hours ago

Most likely explanation: In the Rust version, the compiler can see that expand_iota_views(&input).count() is a pure, loop-invariant expression since input never changes. It folds the whole computation and effectively turns the loop into "add the constant a thousand times". Make it do some work and it will line up to the C++ version.