|
Boost : |
Subject: Re: [boost] [function] type conversion ambiguity?
From: Jonathan Wakely (jwakely.boost_at_[hidden])
Date: 2013-07-15 06:43:38
On 15 July 2013 02:16, Andrew Ho wrote:
> 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.
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk