模板参数的C ++模板参数

时间:2014-07-04 10:15:27

标签: c++ templates

看看这段代码:

template<class T, class Compare>
void foo(const std::set<T, Compare> & bar)
{
    // here I need the comparative function BUT with another type
    // like this:
    if (Compare<float>()(...))
}

这样的东西,但它不起作用:

template<class T, class Compare>
void foo(const std::set<T, Compare<T>> & bar)
...

有可能吗?

1 个答案:

答案 0 :(得分:4)

您需要模板模板参数:

template<class T, template<class> class Compare>

现在Compare模板参数本身就是一个模板。

相关问题