動機爲this example使用std::less/std::greater
。 是否可以使用std::min
或std::max
作爲模板比較器?std :: min/std :: max作爲模板比較器
以下示例引發錯誤:
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);
}
所以有兩個模板參數,'template?' –
pyCthon
@pyCthon是的,你可以。並將它們用作'Test> foo;'。 –
songyuanyao