c++ - boost::bind, std::bind and overloaded functions -


i noticed boost::bind, unlike std::bind, can work overloaded functions when 1 of these functions doesn't have parameters. right? documented?

#include <boost/bind.hpp>  #include <functional> #include <iostream>  void foo() {     std::cout << "::foo() \n"; }  void foo(int) {     std::cout << "::foo(int) \n"; }  int main() {     boost::bind(foo)(); // ok     boost::bind(foo, 0)(); // ok      // std::bind(foo)(); // error     // std::bind(foo, 0)(); // error }  #include <boost/bind.hpp>  #include <functional> #include <iostream>  void foo(int) {     std::cout << "::foo(int) \n"; }  void foo(const std::string&) {     std::cout << "::foo(const std::string&) \n"; }  int main() {     // boost::bind(foo, 0)(); // error     // boost::bind(foo, "str")(); // error      // std::bind(foo, 0)(); // error     // std::bind(foo, "str")(); // error } 

i assume unintended artifact of implementation details, don't think boost provides guarantees automatically resolving correct overload.

std::bind c++11 feature implemented variadic templates.

boost::bind implemented c++03, meaning relies on large number of overloaded function templates.

the 2 quite different in implementation details, , so, assume difference between behavior consequence of that, rather intentional , specified difference.

the boost documentation states this: "an attempt bind overloaded function usually results in error, there no way tell overload meant bound."

in book, means boost docs tell "undefined behavior" whether or not work (compile) or select correct overload.

and far know, should use explicit cast (static_cast) fix signature of overload wish select. true both boost::bind , std::bind, , in sense, both implementations agree.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

javascript - Backbone.js getting target attribute -

html - Repeat image to extend header to fill screen -