1
由于某些原因,迭代两个向量时Iterator比BOOST FOREACH执行速度快得多...我使用Visual Studio 2012并启用了优化。下面是我比较的两段代码...我错过了什么吗?迭代两个向量迭代器比boost_foreach快
typedef boost::tuple<int&, int&> int_ref_tuple;
BOOST_FOREACH(int_ref_tuple tup, boost::combine(v1, v2))
tup.get<0>() = tup.get<1>();
VS
vector<int>::iterator iIter = v1.begin();
vector<int>::const_iterator jIter = v2.begin();
for (;iIter != v1.end();++iIter, ++jIter)
{
//this is faster
}
尝试使用迭代器在'的boost :: combine'的结果,看看是否BOOST_FOREACH是在这种情况下,具有可比性。 – Cameron
visual studio 2012支持C++ 11基于范围的语句。 –
在你的情况下,性能是否重要?不要过早地优化它 –