c++ - How can I test for the last element in a vector when using BOOST_FOREACH? -
i have vector iterate over. final element of vector special case, , i'd test separately. example, may such:
for (iterator = vector.begin(); iterator != vector.end(); ++iterator) { if ((iterator + 1) == (vector.end())) { ... } else { ... } }
i replace iterator boost_foreach
macro. can similar test final element done?
if(!vec.empty()) { boost_foreach(int e, boost::make_iterator_range(vec.begin(), vec.end()-1)) { // handle each element last } // handle last element here }
Comments
Post a Comment