-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Stephen Torri Sent: Saturday, May 19, 2007 12:58 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Converting loop to usingboost::lambda where containers has boost::shared_ptrs
Here is a test program that represents the problem we are trying to solve.
std::for_each ( m_data.begin(), m_data.end(), std::cout << boost::bind ( &Base::to_String, boost::bind::_1, indent_value ) );
[Nat] Heh. With my VC 7.1 compiler (Version 13.10.3077 according to cl /help), the program you sent produces an ICE. But then I'm still on Boost 1.31.1. On the other hand, since the program you sent makes no mention whatsoever of boost::lambda, you can remove the boost::bind qualification from _1 because there's no ambiguity. I did that, and got an error about trying to insert a boost::bind() expression to std::cout. Which would sort of toss us back towards boost::lambda. I thought I'd try using boost::bind on the insertion operator anyway: std::for_each ( m_data.begin(), m_data.end(), boost::bind(operator<<, boost::ref(std::cout), boost::bind ( &Base::to_String, _1, indent_value ) )); but the compiler wasn't buying it. So... maybe there's a way to express what I was trying to write above, or maybe there's a way to express Stuart's boost::lambda::bind construct. But for myself, in this situation I'd consider an explicit 'for' loop the clearest expression of intent. C++ is a truly amazing language that, in many cases, *almost* gets you where you want to go. :-)