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.
精彩评论