One big advantage of std::function over templates is that if you
write a template, you need to put the whole function in the header
file, whereas std::function does not. This can really help if you’re
working on code that will change a lot and is included by many source
files.
If you want to check if a variable of type std::function is currently
holding a valid function, you can always treat it like a boolean: