Looking through the frenzy of metaprogramming BOOST_FOREACH, I see that the collection is copied if it
- r value
- A "lightweight proxy" that you can define for your types by specializing in
boost::foreach::is_lightweight_proxy.
Therefore, lvalue is not copied. Instead, its pointer is considered temporary.
Critical bit:
(true ? 0 : boost::foreach_detail_::or_( \
BOOST_FOREACH_IS_RVALUE(COL) \
, BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
, :
template<typename T>
inline auto_any<T> contain(T const &t, boost::mpl::true_ *)
{
return t;
}
template<typename T>
inline auto_any<T *> contain(T &t, boost::mpl::false_ *)
{
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x570))
return &t;
#else
return boost::addressof(t);
#endif
}
Boost v1.38 .