C++ Logo

std-proposals

Advanced search

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

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Tue, 18 Jul 2023 07:51:57 -0500
You can perform that deduction yourself:

void FuncB(auto const & f) requires requires { std::function(f); } {}

Computing types R and Params is left as an exercise for the reader.

On Tue, 18 Jul 2023 at 06:09, Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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 12:52:11