What is the correct way of using C++11's range-based for?

后端 未结 4 924
面向向阳花
面向向阳花 2020-11-22 10:04

What is the correct way of using C++11\'s range-based for?

What syntax should be used? for (auto elem : container), or for (auto&

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 10:40

    The correct means is always

    for(auto&& elem : container)
    

    This will guarantee the preservation of all semantics.

提交回复
热议问题