http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59182

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to sequoiahead from comment #0)
> The problem is that the compiler is able to convert void Func::pfunc(int) to
> std::function<void(int)>, but can't convert void Func::func() to
> std::function<void()>

No, that's not what's happening.

std::bind(&Func::pfunc, fInstance, std::placeholders::_1) returns a function
object, call it B1, that takes a single argument, as indicated by the
placeholder. B1 is convertible to function<void(int)>, because that type takes
also a single argument, so will pass its argument to B1.

B1 is not convertible to function<void()> because you have to call a
function<void()> with no arguments, and B1 cannot be called with no arguments.

std::function is rejecting your program because it's invalid.  std::bind
doesn't do the same checking, so doesn't reject it, but your program is still
invalid.

This compiles OK:

std::function<void()> voidMemberFunc = std::bind(&Func::func, fInstance);

This bind expression creates a function object that takes no arguments, so can
be stored in a function<void()>.

Reply via email to