How to check if a type is a function

The first time I saw variadic templates, I knew they are useful (as useful as lambdas in my opinion).

Today, we’ll take a look at how to check if some type is a function or not.

Keep in mind that this is compile time code.

The code goes something like this:

This code is using template specialization on function types.

The variadic Args are there just so that we can catch any function, with any number of parameters.

If you want to use the value at runtime, there are a couple of ways to do it, one of them using the above code and decltype, and the one I’ll show you below, using the same method but function templates instead of structs.

That’s just the same thing, but using overloading instead of specialization.

You can use them like this:

where test_fun is defined like: