28
It is evaluated only once. The standard says that the range-based for loop is equivalent to this:
ยง6.5.4 The range-based for statement [stmt.ranged]
{
auto && __range = range-init;
for ( auto __begin = begin-expr,
__end = end-expr;
__begin != __end;
++__begin ) {
for-range-declaration = *__begin;
statement
}
}
with range-init being equivalent to ( bar() ) in your case (the expression you specify, surrounded by parenthesis). That expression is only evaluated once as you can see.