Does a C++11 range-based for loop condition get evaluated every cycle?

后端 未结 1 820
for(auto& entity : memoryManager.getItems()) entity->update(mFrameTime);

If memoryManager contains 1000 items, does memoryManager.getI

相关标签:
1条回答
  • 2020-11-27 19:34

    It is only evaluated once. The standard defines a range-based for statement as equivalent to:

    {
        auto && __range = range-init;
        for ( auto __begin = begin-expr, __end = end-expr; __begin != __end; ++__begin ) {
            for-range-declaration = *__begin;
            statement
        }
    }
    

    where range-init is the expression (surrounded by parentheses) or braced-init-list after the :

    0 讨论(0)
提交回复
热议问题