[function] type conversion ambiguity?
Consider the overloaded functions foo and bar:
typedef boost::function
On 15 July 2013 02:16, Andrew Ho wrote:
Consider the overloaded functions foo and bar:
typedef boost::function
function_type1; typedef boost::function function_type2; typedef std::function
function_type3; typedef std::function function_type4; void foo(const function_type1 &a) { // blah }
void foo(const function_type2 &a) { // blah }
void bar(const function_type3 &a) { // blah }
void bar(const function_type4 &a) { // blah }
calling foo with a function pointer is ambiguous, but calling bar is not:
void doit1(void) {}
void doit2(int) {}
foo(&doit1); // ambiguous bar(&doit2); // compiles and runs fine
This occurs despite the fact that boost::function
(&doit2) can be caught at compile time.
Actually they should both be ambiguous according to the C++11 standard, but it looks as though your standard library already implements the proposed resolution to http://cplusplus.github.io/LWG/lwg-active.html#2132 (I implemented it for libstdc++ and I know libc++ implements it too.)
Is there some way to fix the definition of boost::function such that this is no longer ambiguous?
Implement the resolution to LWG 2132.
participants (2)
-
Andrew Ho
-
Jonathan Wakely