How to pass a template function in a template argument list

后端 未结 2 698
温柔的废话
温柔的废话 2020-12-01 11:59

Suppose I have a template function:

template
T produce_5_function() { return T(5); }

How can I pass this ent

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 12:54

    How about wrapping that function?

    template
    struct produce_5_function_wrapper {
        T operator()() const { return produce_5_function(); }
    };
    

    Then you can use the wrapper instead of the function:

    int five = client_template< produce_5_function_wrapper >()();
    

    Using the template function alone will not work, there's no such thing as "template template functions".

提交回复
热议问题