Correct definition of a function that takes callable as its input

86 views Asked by At

Is it correct to define a function foo that takes as its input a callable as follows:

template< typename callable_t >
void foo( callable_t f )
{
  // code that calls f 
}

Do we need any type traits to ensure that f is a callable? I would say "no" since the compiler will throw an error in case that I pass, for example, an int to foo and try to call it.

What do you think?

0

There are 0 answers