When using BOOST_FOREACH is the following code safe?
BOOST_FOREACH (const std::string& str, getStrings()) { ... } ... std::vector<std::string> getStrings() { std::vector<std::string> strings; strings.push_back("Foo"); ... return strings; }
Or should I grab a copy of the container before calling BOOST_FOREACH , for example:
const std::vector<std::string> strings = getString(); BOOST_FOREACH (const std::string& str, strings) { ... }
In the first example, is there any danger that BOOST_FOREACH might call getStrings() several times?
Rob
source share