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基於範圍的語句。 –
在你的情況下,性能是否重要?不要過早地優化它 –