BOOST_FOREACH and a vector

KaiserJohaan picture KaiserJohaan · Dec 24, 2012 · Viewed 11.4k times · Source

I have a vector of Scenes, vector<Scene>. What is the correct way to iterate over the elements, as reference or not?

For example this:

BOOST_FOREACH(Scene scene, mScenes)
{
       .....
}

Does the macro copy the Scene for each iteration over the vector, or does it use a reference behind the scenes?

So is it any different from this:

BOOST_FOREACH(Scene& scene, mScenes)
{
       .....
}

Answer

kassak picture kassak · Dec 24, 2012

BOOST_FOREACH behaves exactly as you tell him, by value, reference or const reference