ryanhaining / cppitertools

Implementation of python itertools and builtin iteration functions for C++17
https://twitter.com/cppitertools
BSD 2-Clause "Simplified" License
1.37k stars 115 forks source link

`iter::product` of `iter::range`'s #16

Closed iliocatallo closed 10 years ago

iliocatallo commented 10 years ago

Hi,

I was trying to compose iter::product with iter::range so as to iterate over all the coordinate pairs of a matrix. Unfortunately, I can't manage to get it work with iter::range, wheres there's no problem with ranges generated with boost::irange. Here's a showcase example:

int main() {

    // this work
    for (auto&& ij: iter::product(boost::irange(0, 10), boost::irange(0, 5))) {
        std::cout << std::get<0>(ij) << "," << std::get<1>(ij) << std::endl;
    }

    // this does not work
    for (auto&& ij: iter::product(iter::range(10), iter::range(5))) {
        std::cout << std::get<0>(ij) << "," << std::get<1>(ij) << std::endl;
    }   
}

clang reports:

note: copy assignment operator of 'Iterator' is implicitly deleted because field 'step' is of const-qualified type 'const int'
                    const T step;

Thanks and sorry for submitting two reports in a row!

ryanhaining commented 10 years ago

test case added to testproduct.cpp. const qualifier removed from step. should work as intended now. no need for apologies, the reports are much appreciated.