Is there a convenient way to get the index of the current container entry in a C++11 foreach loop, like enumerate in python:
enumerate
for idx, obj in enu
If you have access to Boost it's range adaptors can be used like this:
using namespace boost::adaptors; for (auto const& elem : container | indexed(0)) { std::cout << elem.index() << " - " << elem.value() << '\n'; }
Source (where there are also other examples)