Given a function like this:
template<typename functor>
void foo(functor const& f)
{
if (f)
f(1, 2);
}
I want to be able to assign a default value where f
can be set to something similar to NULL
. Also, it would be possible sufficient to make a bogus call to an empty function. Is there anything I can use (from the standard or boost
-library) without creating such a thing by myself?
Use an empty functor and use as default template parameter. You can't use something like NULL because you have no pointer:
class X
{
void operator()(...) {}
};
template <typename functor = X>
void foo(functor const& f = X())
{
f(...);
}
Either write an overload that takes and does nothing, or pass a no-op functor to foo
.
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