C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Template Type Resolution -- Special Rules for std::function

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 18 Jul 2023 13:32:45 +0200
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_at_[hidden]> Gesendet:Di 18.07.2023 13:09 Betreff:[std-proposals] Template Type Resolution -- Special Rules for std::function An:std-proposals <std-proposals_at_[hidden]>; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; 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_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-07-18 11:32:48