开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜