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

[c++17] enumerate should work with structured bindings #33

Closed ryanhaining closed 7 years ago

ryanhaining commented 7 years ago

Currently this is invalid with c++17

for (auto&& [i, e] : iter::enumerate(seq)) {
    // ...
}

because the object returned by enumerate's iterator's operator* is a subclass of pair with more data members. In some way, the above should work.

dnbaker commented 7 years ago

Maybe add a plainer iteration type which with an operator implicit type conversion which strips out the extra metadata?

ryanhaining commented 7 years ago

I was thinking of providing get for the yielded type. If I don't care about compatibility I could have it yield pair, which I should've done in the first place, seems a little late for that change now though.

ryanhaining commented 7 years ago

Turns out all I needed was tuple_size and tuple_element. std::get(std::pair) took care of the rest.