Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2008-07-14 10:18:01


David Abrahams wrote:
> on Mon Jul 14 2008, "Robert Jones" <robertgbjones-AT-gmail.com> wrote:
>
>> On Fri, Jul 11, 2008 at 4:41 PM, David Abrahams <dave_at_[hidden]> wrote:
>>
>> Note that std::endl can cause you big troouble, but since you're using
>> '\n' above I don't see a reason to worry. You do need something like
>> "using namespace boost::lambda;" to make "_1" valid, though.
>>
>> Back in the office on Monday morning, and applying my new found
>> knowledge my Boost-using code compiles perfectly, but for one little
>> snag!
>>
>> For brevity and clarity I posted example code using '\n' line terminators.
>> However my real code uses endl - which is indeed causing me big troouble!
>>
>> Are there any techniques for successfully using std::endl in lamda functions?
>
> Not any good ones. The problem is that endl is a function template and
>
> ostream << std::endl;
>
> matches the operator<< overload for stream manipulators, which are
> function pointers, something like:
>
> ostream& operator<<( ostream, some-concrete-function-pointer-type );
>
> so the compiler implicitly specializes std::endl<X...> so that it gets
> the right function pointer. It's nasty.

I don't know, phoenix has been using std::endl since day one.
All the tests and examples I have use std::endl, not '\n'.
I don't know now the exact technique that I did, but I recall
working around this a long time ago. I'll go dig it up.
I never really understood why lambda barfs with std::endl.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk