template<typename TCallable>
void Fun(TCallable c){
...
}
How can I indicate that the c
in the foregoing code must have some specific signature (let's say int(double, double)
) without using std::function?
Looks like you can just add static_assert(std::is_same<decltype(c(0.0,0.0)), int>::value, "c must take two doubles and return int")
.
If you want several Fun
functions for different Callable
s, then static_assert()
won't help you, but you can use SFINAE, e.g.
// version for int(double,double)
template<typename Callable>
auto Fun(Callable c)
-> typename
std::enable_if<std::is_same<decltype(c(0.0,0.0)),int>::value>::type
{ /* ... */ }
// version for int(double,double,double)
template<typename Callable>
auto Fun(Callable c)
-> typename
std::enable_if<std::is_same<decltype(c(0.0,0.0,0.0)),int>::value>::type
{ /* ... */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With