Boost logo

Boost :

Subject: [boost] [function] type conversion ambiguity?
From: Andrew Ho (helloworld922_at_[hidden])
Date: 2013-07-14 21:16:16


Consider the overloaded functions foo and bar:

typedef boost::function<void(void)> function_type1;
typedef boost::function<void(int)> function_type2;

typedef std::function<void(void)> function_type3;
typedef std::function<void(int)> 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<void(void)>(&doit2) can be
caught at compile time.

Is there some way to fix the definition of boost::function such that this is
no longer ambiguous?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk