
Eric Niebler wrote:
Here is an interesting way to "distinguish" between L-values and R-values.
<snip> I just committed to boost-sandbox an experimental new version of BOOST_FOREACH that uses the technique I described to correctly handle even const rvalue container expressions. I was unable to find a way to detect const r-value expressions at compile-time, so instead I use a runtime check along with boost::variant. It's fully inlineable, so the runtime check should be optimized away, although the use of variant will incur a small perf hit (not yet measured). The r-value detection stuff is rather subtle, and it requires a very compliant compiler. (In fact, I haven't yet convinced myself it's entirely kosher.) It works on gcc 3.3.3, but not on VC++, so the word to the wise is: don't use BOOST_FOREACH with const r-value container expressions on VC++. No doubt there are other compilers which are also broken with regard to the const r-value detection stuff. If anybody is interested, grab the code and try it with your favorite compiler and let me know how it works out. If it doesn't compile, try #defining BOOST_FOREACH_NO_CONST_RVALUE_DETECTION and see if that fixes the problem. It lives in boost-sandbox at ROOT/boost/foreach.hpp. I'm also attaching it here along with a simple driver. -- Eric Niebler Boost Consulting www.boost-consulting.com