Convert for_each to C++11 loops