C++"延迟"模板参数

Any*_*orn 3 c++ templates

有没有直接的方法来做到以下几点:

template < class >
struct f {};

template < class F >
void function() {
    F<int>();  //for example
    // ? F template <int>();
}

function < f >();
Run Code Online (Sandbox Code Playgroud)

我通过使用模板结构的额外类来解决方法.我想知道是否有可能直接这样做.

谢谢

AnT*_*AnT 7

模板模板参数的正确语法如下

template < class > struct f {}; 

template < template <class> class F > 
void function() { 
    F<int>();  //for example 
} 

...     
function < f >()
Run Code Online (Sandbox Code Playgroud)

  • @sharptooth:这里没什么好看的.就像普通的函数参数一样,如果您没有使用模板参数,则不必为其命名. (4认同)