You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
auto vec = std::vector<int>{1, 2, 3, 4};
for (auto [element, index] : sharp::enumerate(vec)) {
cout << index << " : " << element << endl;
}
This code will work in C++17 with structured bindings, but will not work with C++14. The closest behavior in C++14 is with std::tie()
auto range = std::vector<int>{1, 2, 3, 4};
auto integer = int{};
auto index = std::size_t{};
for (std::tie(integer, index) : sharp::enumerate(range)) {
cout << index << " : " << element << endl;
}
This is also fine till support for C++17 is common. Then it will be easy to switch to the nice structured bindings syntax.
The text was updated successfully, but these errors were encountered:
aary
changed the title
Provide an interface that mimics Python's enumerate()
Provide an interface that mimics Python's enumerate() or Go's range()Aug 25, 2017
The goal is to copy Python's
enumerate()
utilityor Go's range keyword
In C++ this might look like the following
This code will work in C++17 with structured bindings, but will not work with C++14. The closest behavior in C++14 is with
std::tie()
This is also fine till support for C++17 is common. Then it will be easy to switch to the nice structured bindings syntax.
The text was updated successfully, but these errors were encountered: