|
Boost : |
From: Darren Cook (darren_at_[hidden])
Date: 2004-01-03 21:36:53
In this code:
std::string str("...");
boost::regex re("...");
MyFunctor callback(this);
int matches=boost::regex_grep(callback,str,re);
if(matches==0)return 0;
if(callback.has_errors)return 2;
return 1;
it always returns 1 when it should return 2, and this is because the functor
is being copied rather than passed by reference.
Is there a reason it is copied? Is passing functors by reference a Bad
Thing, and if so could someone point me to an article or discussion summary
on this?
In the above case I'm passing in a "this" pointer, so I'll just move
"has_errors" from the functor into the client class. But this is nearly as
ugly as using a global variable: the variable will only ever be set by the
functor, and only ever read by this block of code.
Darren
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk