基于MSVC 10范围的循环 [英] MSVC 10 range based for loop
问题描述
当前在一个大型的c ++项目中,我们正在为以下循环添加一堆新样式:
Currently in a large c++ project we are working on we have a bunch of the new style for loops like the following:
for (auto& value : values)
到目前为止,我们仅使用gcc 4.6进行编译。最近,一些代码库正在移植到Windows,一些开发人员希望在msvc ++ 10中进行编译,但似乎新的for循环语法尚未得到完全支持。
Up till now we have been compiling exclusively with gcc 4.6. Recently some of the codebase is being ported to windows and some of the developers want to compile in msvc++ 10 but it seems as though the new for loop syntax is not fully supported yet.
迫切需要不必重写所有出现此语法的地方。
It would be highly desirable to not have to re-write all the places where this syntax occurs.
解决此问题的最佳方法是什么?
What is the best way to work around this problem?
更新:似乎此问题已在MSVC11中解决。
Update: It looks as though this issue is resolved in MSVC11.
推荐答案
您可以使用 Boost.Foreach :
//Using Xeo's example:
BOOST_FOREACH (auto& e, values) {
std::cout << e << " ";
}
这篇关于基于MSVC 10范围的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!