Boost logo

Boost Users :

From: Kenneth Yarnall (yarnall_at_[hidden])
Date: 2002-09-13 12:22:18


On Fri, 2002-09-13 at 12:22, Jaakko Jarvi wrote:
> Hi Ken,
>
> > for_each(ell.begin(), ell.end(), cout << _1 << endl);
>
> > Any suggestions? I am aware that I can replace endl by '\n' and get a
> > compilable program. I worry that this problem extends to other
> > manipulators...
> >
>
> It's not a bug, just an unfortunate restriction.

Thanks for the quick response.

> Example: endl is not now allowed in std::cout statements in a Lambda
> expression. '\n' has to be used instead.
>
> -- This is because the old style streams were not templates and the new
> style ones are. Also, endl has been changed from a non-template function
> to a template function and one cannot take the address of a function
> template (withtout instantiated it at the same time. For example, in _1 <<
> endl, the library does not know what the type of the stream that later is
> substituted for _1 will be. -- Jaakko Jarvi

So if I explicitly list the template parameters, does it work? Hmmm...

No, this doesn't work:

for_each(ell.begin(), ell.end(),
    cout << _1 << endl<char, char_traits<char> >);

I was hopeful --- I'm pretty sure I have the syntax right. I'm simply
curious now: is it possible to make this work?

Ken

-- 
Ken Yarnall
Dept. of Mathematical Sciences               Lebanon Valley College
Assoc. Professor of Math and CS       (717)867-6085 yarnall_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net