Pass functor to constructor
I have a class that basically needs to store a functor given in the
constructor, similar to this:
template <class T>
class Foo {
private:
T func;
public:
Foo(T f) : func(f) { }
}
However, to create a new instance of the Foo class, the I can't seem to do
this:
Foo foo(std::less<int>());
because T is a class template parameter. I have to use this clunky syntax
instead:
Foo<std::less<int>> foo(std::less<int>());
Is there a better way to do this, without writing the type of the functor
twice?
No comments:
Post a Comment