Index: boost/foreach.hpp =================================================================== --- boost/foreach.hpp (revision 74924) +++ boost/foreach.hpp (working copy) @@ -1052,22 +1052,49 @@ namespace boost { namespace foreach_detail_ { + template + inline typename boost::mpl::if_::type &add_const_if(T &t) + { + return t; + } + template typename remove_cv::type>::type decay_copy(T &&); template T const add_const_if_rvalue(T &&); }} -# define BOOST_FOREACH_AUTO_OBJECT(NAME, EXPR) \ + +# define BOOST_FOREACH_IS_RVALUE(COL) \ + (true ? 0 : boost::foreach_detail_::is_rvalue(COL)) + +# if (BOOST_WORKAROUND(__GNUC__, == 4) && (__GNUC_MINOR__ == 4) && !defined(BOOST_INTEL) && !defined(BOOST_CLANG)) +# define BOOST_FOREACH_AUTO_OBJECT(NAME, EXPR) \ if (bool BOOST_PP_CAT(NAME, _defined) = false) {} else \ + for (auto NAME = (EXPR); !BOOST_PP_CAT(NAME, _defined); BOOST_PP_CAT(NAME, _defined) = true) +# else +# define BOOST_FOREACH_AUTO_OBJECT(NAME, EXPR) \ + if (bool BOOST_PP_CAT(NAME, _defined) = false) {} else \ for (decltype(boost::foreach_detail_::decay_copy(EXPR)) NAME = (EXPR); \ !BOOST_PP_CAT(NAME, _defined); BOOST_PP_CAT(NAME, _defined) = true) +# endif // If EXPR is an rvalue, bind it to a const rvalue reference. -# define BOOST_FOREACH_AUTO_REF_REF(NAME, EXPR) \ +# if (BOOST_WORKAROUND(__GNUC__, == 4) && (__GNUC_MINOR__ == 4) && !defined(BOOST_INTEL) && !defined(BOOST_CLANG)) +# define BOOST_FOREACH_AUTO_REF_REF(NAME, EXPR) \ + if (bool BOOST_PP_CAT(NAME, _tmp_defined) = false) {} else \ + for (auto &&BOOST_PP_CAT(NAME, _tmp) = (EXPR); \ + !BOOST_PP_CAT(NAME, _tmp_defined); BOOST_PP_CAT(NAME, _tmp_defined) = true) \ if (bool BOOST_PP_CAT(NAME, _defined) = false) {} else \ + for (auto &&NAME = boost::foreach_detail_::add_const_if< boost::is_rvalue_reference >( \ + BOOST_PP_CAT(NAME, _tmp)); \ + !BOOST_PP_CAT(NAME, _defined); BOOST_PP_CAT(NAME, _defined) = true) +# else +# define BOOST_FOREACH_AUTO_REF_REF(NAME, EXPR) \ + if (bool BOOST_PP_CAT(NAME, _defined) = false) {} else \ for (decltype(boost::foreach_detail_::add_const_if_rvalue(EXPR)) &&NAME = (EXPR); \ !BOOST_PP_CAT(NAME, _defined); BOOST_PP_CAT(NAME, _defined) = true) +# endif #elif defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION) ///////////////////////////////////////////////////////////////////////////////