The lifetime of a temporary used as the range-expression is extended till the end of the loop.
Nevertheless, try these:
Do you still get the same error if you write:
1 2 3 4 5 6 7
for( /*const auto&*/ auto str : query( mmap, key, attribute ) ) {
if ((str)=="solar system" {
std::cout << "Pluto is part of our solar system" << endl;
}
}
Do you get the same error even if you write:
1 2 3 4 5 6 7 8
constauto /*&*/ range = query( mmap, key, attribute ) ; // *** EDIT
for( /*const auto&*/ auto str : range ) {
if ((str)=="solar system" {
std::cout << "Pluto is part of our solar system" << endl;
}
}