And the reason I don't use the Foo::less_than() function is that I don't own the Foo class and it doesn't have that implemented in my real code base. (I just added it here as an example) I can't modify Foo. All that Foo provides is the Foo::Bar() function.

And the reason I don't use the Foo::less_than() function is that I don't own the Foo class and it doesn't have that implemented in my real code base. (I just added it here as an example) I can't modify Foo. All that Foo provides is the Foo::Bar() function.

Sorry Dan. I misread your initial comment. I though you wanted to call less_equal not Bar.

I don't know how to do this with bindings. My C++ knowledge is rusty. My C++ template meta-programming knowledge is poor.

Yep. I came up with that functor too. It's fine when you just have one function method you are using in std::remove_if. But in my case there are several and coming up with a functor for each one is a maintenance headache. For example:

Yep. I came up with that functor too. It's fine when you just have one function method you are using in std::remove_if. But in my case there are several and coming up with a functor for each one is maintenance headache. For example:

There I bind the address of the function, notate (using '_1') that there is one parameter that will be passed in by the caller of the bind object, and pass in the value 3 to the second parameter. Note I also made the function static and added the parameter required by the remove_if predicate as noted in STL docs (http://www.cplusplus.com/reference/stl/list/remove_if/, I use this website at work). I haven't compiled this code, as I don't have a build of boost setup here at home, but I use it all the time at work. This problem would be a solvable using lambdas in C++0x. Boost lambdas are ugly and I personally wouldn't use nor encourage them.

ShortCutMan, is there a way to use boost's bind (not boost's lambda bind) without calling Foo's less_equal? That is can the call to Bar() be build into the bind expression?

The OP said subsequently that less_equal doesn't actually exist in the class he's actually trying to use, and he can't change the class. And there's apparently more than just Bar() he needs to use in these kinds of expressions.

ShortCutMan, is there a way to use boost's bind (not boost's lambda bind) without calling Foo's less_equal? That is can the call to Bar() be build into the bind expression?

The OP said subsequently that less_equal doesn't actually exist in the class he's actually trying to use, and he can't change the class. And there's apparently more than just Bar() he needs to use in these kinds of expressions.

jiminaus, do you ever sleep? And yes, (unfortunately) I can't add to the Foo class by adding Foo::less_equal().

Quote:

myFoos.remove_if(boost::bind(&Foo::Bar, _1) <= 3);

Winner! Yes, that is exactly what I was hoping for (and I agree that boost is awesome). I also can't wait to upgrade our compilers to C++ 0x to take advantage of lambdas. As of now, I will look to boost.

I will now spend some quality time with stl, boost, and my compiler. Thanks to everyone.

There I bind the address of the function, notate (using '_1') that there is one parameter that will be passed in by the caller of the bind object, and pass in the value 3 to the second parameter. Note I also made the function static and added the parameter required by the remove_if predicate as noted in STL docs (http://www.cplusplus.com/reference/stl/list/remove_if/, I use this website at work). I haven't compiled this code, as I don't have a build of boost setup here at home, but I use it all the time at work. This problem would be a solvable using lambdas in C++0x. Boost lambdas are ugly and I personally wouldn't use nor encourage them.

The boost lambdas may be ugly but I would submit so is writing extra one off functors/functions. I hear what you are saying though. Unfortunately, we can't upgrade yet to C++0x to take advantage of the new built in lambda support.

This allows me to write less code. Now I must make sure I write concise comments explaining what is happening at the point of the std::list::remove_if() call.

Last edited by danwilliams; May 4, 2011 at 11:05 AM.
Reason: clarification

I see what you mean also, I'm probably just used to seeing boost bind more so than boost lambda. Sometimes I have seen people write nested structs in the calling function if it is once off, or just put it in an anonymous namespace since it doesn't really need to be a class member function.