开发者

New C++11 range-for (foreach) syntax: which compilers support it?

开发者 https://www.devze.com 2023-02-11 06:47 出处:网络
I saw this c++11 code fragment in this BoostCon presentation by Jeremy Siek: deque<int> topo_order;

I saw this c++11 code fragment in this BoostCon presentation by Jeremy Siek:

deque<int> topo_order;
topological_sort(g, front_inserter(topo_order));

for (int v : topo_order){ //line 39
    cout << tasks[v] << endl;
}

Upon trying to compile in gcc there is the following error:

main.cpp:39: error: expected initializer before ‘:’ token

whic开发者_StackOverflow中文版h then got me wondering, which compilers actually support this syntax?


Well, at least GCC supports it in 4.6 (feature is called "Range-based for"). If you already have the latest version, don't forget to add the -std=c++0x option.


In addition to gcc versions later than version 4.6, both Clang 3.0 and Visual C++ 11 (as of the Visual C++ 11 Beta) both support this C++11 language feature.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号