[lambda] std::string::find

First, sorry for this total newbie question, i'm trying to do something like this: std::for_each ( std::istream_iterator<std::string>(ss), std::istream_iterator<std::string>(), boost::lambda::if_then ( !(boost::lambda::bind(&std::string::substr, boost::lambda::_1, 0, 1) == _ignore) && !boost::lambda::bind(&std::string::empty, boost::lambda::_1), (boost::lambda::bind(&std::string::find, boost::lambda::_1, _ignore), // compiler complains here ---------------------------------<snip>---------------------------------------------------------------------- i'm getting the following error: Error 23 error C2784: 'const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<3,boost::lambda::function_action<3,T>>,detail::bind_tuple_mapper<const Arg1,const Arg2,const Arg3>::type>> boost::lambda::bind(const Arg1 &,const Arg2 &,const Arg3 &)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type' am i not supplying the correct amount of parameters to the find method? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

On Sun, 11 Feb 2007 21:24:42 -0000, Bob Quampen <0377521021@iol.cz> wrote:
(boost::lambda::bind(&std::string::find, boost::lambda::_1, _ignore),
[snip] boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<3,boost::lambda::function_action<3,T>>,detail::bind_tuple_mapper<const
Arg1,const Arg2,const Arg3>::type>> boost::lambda::bind(const Arg1 &,const Arg2 &,const Arg3 &)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'
am i not supplying the correct amount of parameters to the find method?
Sort of, there are actually two problems here. The first is that std::string::find has 2 overloads with one parameter and the compiler doesn't know which one to use. The solution is to cast it to the correct type, ie. static_cast<std::string::size_type (std::string::*)(const std::string&)>(&std::string::find) Which is pretty ugly. The second problem is that this won't work if find is defined as a two argument method, with a default value for the second argument (as it seems to be for gcc). In which case you do need to use a second argument. This is pretty messy and hard to do portably (unless anyone knows better?). I wouldn't use Boost.Lambda for anything this complicated. I think some work has gone into making this kind of thing easier in phoenix. But Boost.ForEach is probably the best solution here. Or you could put the loop body in a separate function. Hope that helps. Daniel
participants (2)
-
Bob Quampen
-
Daniel James