Hi there.
I have a recent CVS version of Boost installed, and am using g++ v3.2. I
tried to compile the following program:
-----------lambda_test.cpp------------
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include
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. This is an extract form Lambda wiki page: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Lambda 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 Jaakko
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
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
); I was hopeful --- I'm pretty sure I have the syntax right. I'm simply curious now: is it possible to make this work?
Explicit specialization should work, just tested under gcc3.2.
Here's another option, a helper function manip
that takes a stream and a manipulator and chooses the appropriate
instantiation of the endl template. Much nicer to just give the stream
object rather than the stream template args:
#include "boost/lambda/lambda.hpp"
#include <iostream>
namespace boost {
namespace lambda {
template
Ken -- Ken Yarnall Dept. of Mathematical Sciences Lebanon Valley College Assoc. Professor of Math and CS (717)867-6085 yarnall@lvc.edu
Yahoo! Groups Sponsor ADVERTISEMENT [d_300x250_071_4for49_1.gif]
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
-- -- -- Jaakko Järvi email: jajarvi@cs.indiana.edu -- Post Doctoral Fellow phone: +1 (812) 855-3608 -- Pervasive Technology Labs fax: +1 (812) 855-4829 -- Indiana University, Bloomington
participants (3)
-
Jaakko Jarvi
-
Ken Yarnall
-
Kenneth Yarnall