I am learning default template argument today and everything is ok at first, but now I encounter some problems.
template <typename T, typename F = std::less<T>>
int compare(const T &v1, const T &v2, F f = F()) {
if (f(v1, v2)) return -1;
if (f(v2, v1)) return 1;
return 0;
}
I know F
is the type of a callable object and f
is a callable object, but what does the F()
mean? A type and an operator()?
And what makes me more confused is that F()
doesn't accept anything whereas f(v1, v2)
accepts 2 objects. The initialization confused me a lot.
If anyone can help me figure out these codes, I would be very grateful.Thx.
Aucun commentaire:
Enregistrer un commentaire