
Michael Kochetkov <michael.kv@gmail.com> writes:
Hello, as far as I subscribed to boost mail list for a reason I have decided to share an interesting (at least for me) observation of boost::function facility I have encountered several years ago. The observation is about the cost of the solution and you probably may be interested if you use boost in your production.
The standard and boost leave the return type of bind (and mem_fn) undefined as the actual implementation of the returned binder can vary, which makes it impossible to use reliably on non C++11 compilers. I think most users are aware of the cost implications that function has and try to pass the result of bind in context where the type can be deduced. Maybe a word of warning wouldn't be too bad, though.
Let us consider the following code: #include <boost/bind.hpp> #include <boost/function.hpp>
inline int g(int i) { return ++i; }
int main() { // AAAAA boost::function< int (int) > f1 = boost::bind(&g, _1 ); f1(1);
// BBBB boost::_bi::bind_t<int,int (*)(int),boost::_bi::list1<boost::arg<1>
f2 = boost::bind(&g, _1 ); f2(1);
// CCCC auto f3 = boost::bind(&g, _1 ); f3(1); }