On Wed, 1 Sep 2004 22:11:28 +0300, Peter Dimov
Maximilian Wilson wrote:
I am getting another compiler error when trying to use the lambda library. Current experiment is string extraction. I'm trying to create a lambda(x) that pushes any char passed to it onto a particular string.
string s2; void (std::string::*ft)(char) = &std::string::push_back; // extract function pointer because push_back is overloaded char c = 'n'; bind<void>(ft, var(s2), _1, 1)(c);
bind( ft, var(s2), _1 )( c );
ft has two arguments, 'this' and a char. No need for the trailing '1'.
Try
(s2 += _1)( c );
too.
That's true about the two arguments--I used the wrong function signature, so the extraneous 1 will be ignored. That still can't be the whole solution, though, because that would be a runtime error and not a compiler error in lambda. You're actually right about (s+=_1)--thank you. After I read your message, I went back and looked more closely at the types I was using. It turns out to be an elementary C++ error unrelated to lambda. I thought push_back had the interface of append, and I switched the params (size_t, char) for (char, int). No wonder the compiler was confused. This works fine: string&(string::*ft)(std::allocate<char>::size_type,char) = &string::append; bind(ft, var(s2), 1, _1); So there is nothing fundamentally wrong with my understanding of the lambda library. Good. Now I'm ready to start using it. Thanks muchly, Max -- Sometimes I think decisions through, weigh the consequences, decide it is not a good idea, but blind myself and make it anyway. I do not think this is a good thing to do, but it might be. Humans are endowed with both reason and emotion for a reason. -Tara Greenwood