As a lazy developer, I like to use this trick to specify a default function:
template
There is no standard functor that does this, but it is easy enough to write (though the exact form is up for some dispute):
struct identity {
template
constexpr auto operator()(U&& v) const noexcept
-> decltype(std::forward(v))
{
return std::forward(v);
}
};
This can be used as follows:
template
void index(std::array &x, Function&& f = Function())
{
for (unsigned int i = 0; i < Size; ++i) {
x[i] = f(i);
}
}