Those work:

 

#include<functional>

void FuncA(std::function<void(int)> const &) {}

template<typename R, typename... Params>
void FuncB(std::function<R(Params...)> const &) {}

void Monkey(int) {}

int main(void)
{
    FuncA(Monkey);

    FuncB(static_cast<std::function<decltype(Monkey)>>(Monkey));

    std::function M2 = Monkey;
    FuncB(M2);
}


 

-----Ursprüngliche Nachricht-----
Von: Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Di 18.07.2023 13:09
Betreff: [std-proposals] Template Type Resolution -- Special Rules for std::function
An: std-proposals <std-proposals@lists.isocpp.org>;
CC: Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>;
Consider the following example code:

#include <functional>

void FuncA(std::function<void(int)> const &) {}

template<typename R, typename... Params>
void FuncB(std::function<R(Params...)> const &) {}

void Monkey(int) {}

int main(void)
{
   FuncA(Monkey);
   FuncB(Monkey);    // Fails to compile
}

I think 'std::function' should be given special treatment by compilers
so that the above compiles.

Something along the lines of:
   When the compiler is trying to instantiate a template with an
std::function parameter, and a function pointer is passed as the
argument, the full type of the std::function can be implicitly
determined from the type of the function pointer.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals