bind vs. mem_fn with data members

This surprised me; should it have? #include <boost/bind.hpp> #include <boost/mem_fn.hpp> struct X { int y; }; int main() { boost::mem_fn(&X::y); // OK boost::bind(&X::y); // Error! } -- Dave Abrahams Boost Consulting www.boost-consulting.com

On Mar 11, 2004, at 9:42 AM, David Abrahams wrote:
This surprised me; should it have?
#include <boost/bind.hpp> #include <boost/mem_fn.hpp>
struct X { int y; };
int main() { boost::mem_fn(&X::y); // OK boost::bind(&X::y); // Error! }
I'm not seeing any surprises. mem_fn(&X::y) produces a function object that takes one parameter. Therefore the bind equivalent needs an argument or a placeholder: bind(&X::y, _1); -Howard

Howard Hinnant <hinnant@twcny.rr.com> writes:
On Mar 11, 2004, at 9:42 AM, David Abrahams wrote:
This surprised me; should it have?
#include <boost/bind.hpp> #include <boost/mem_fn.hpp>
struct X { int y; };
int main() { boost::mem_fn(&X::y); // OK boost::bind(&X::y); // Error! }
I'm not seeing any surprises. mem_fn(&X::y) produces a function object that takes one parameter. Therefore the bind equivalent needs an argument or a placeholder:
bind(&X::y, _1);
DUH!! Thanks, Howard! -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Howard Hinnant