Skip to main content
added 269 characters in body
Source Link
Jarod42
  • 227.5k
  • 15
  • 214
  • 350

Function (pointer) is not a std::function, so doesn't work for deduction.

You might make Ts... non deducible in that context

template<typename T, typename ... Args> void foo(std::function<void(T, std::type_identity_t<Args>...)> fcn, Args ... args) { // Some code that calls fcn } 

Demo

or drop std::function completely

template<typename T, typename F, typename ... Args> requires (std::is_invocable<F, T, Args...>::value) void foo(F fcn, Args&& ... args) { // Some code that calls fcn } 

Demo

Function (pointer) is not a std::function, so doesn't work for deduction.

You might make Ts... non deducible in that context

template<typename T, typename ... Args> void foo(std::function<void(T, std::type_identity_t<Args>...)> fcn, Args ... args) { // Some code that calls fcn } 

Demo

Function (pointer) is not a std::function, so doesn't work for deduction.

You might make Ts... non deducible in that context

template<typename T, typename ... Args> void foo(std::function<void(T, std::type_identity_t<Args>...)> fcn, Args ... args) { // Some code that calls fcn } 

Demo

or drop std::function completely

template<typename T, typename F, typename ... Args> requires (std::is_invocable<F, T, Args...>::value) void foo(F fcn, Args&& ... args) { // Some code that calls fcn } 

Demo

Source Link
Jarod42
  • 227.5k
  • 15
  • 214
  • 350

Function (pointer) is not a std::function, so doesn't work for deduction.

You might make Ts... non deducible in that context

template<typename T, typename ... Args> void foo(std::function<void(T, std::type_identity_t<Args>...)> fcn, Args ... args) { // Some code that calls fcn } 

Demo