#include required to use initializer list in range-based for?

前端 未结 2 1381
眼角桃花
眼角桃花 2021-01-17 11:40

The final C++11 standard includes provisions for range-based for to \"just work\" for native arrays without having to include or any other head

2条回答
  •  醉酒成梦
    2021-01-17 12:31

    I'd say yes. According to §6.5.4[stmt.ranged]/1, the statement

    for (auto i : { 1, 2, 3, 4, 5 })
        ...
    

    is just equivalent to

    auto&& __range = { 1, 2, 3, 4, 5 };
    ...
    

    and that means an initializer_list is used, and the header needs to be included.

提交回复
热议问题