Motivated by this example using std::less/std::greater
.
Is it possible to use std::min
or std::max
as a template comparator?
The following example throws the error:
error: type/value mismatch at argument 1 in template parameter list for 'template<class C> class Test'
#include <functional>
#include <algorithm>
template <typename C>
class Test
{
public:
int compare(int x, int y)
{
return C()(x, y);
}
};
int main() {
Test<std::min<int>> foo;
Test<std::max<int>> bar;
foo.compare(1, 2);
bar.compare(1, 2);
}