BOOST_FOREACH
을 사용할 때 다음 코드가 안전합니까?BOOST_FOREACH 사용법을 수정 하시겠습니까?
BOOST_FOREACH (const std::string& str, getStrings())
{
...
}
...
std::vector<std::string> getStrings()
{
std::vector<std::string> strings;
strings.push_back("Foo");
...
return strings;
}
또는 내가 BOOST_FOREACH
를 호출 전에 용기 의 사본을 잡아해야, 예컨대 : 첫 번째 예에서
const std::vector<std::string> strings = getString();
BOOST_FOREACH (const std::string& str, strings)
{
...
}
BOOST_FOREACH
이 getStrings()
여러 번 호출 끝낼 수있는 위험이 있습니다?
간결하면서도 인상적인 대답입니다! (+1, 물론) –
그것은 그들의 설명서에서 인용구입니다 :) –