C++ template argument type deduction

后端 未结 2 1421
抹茶落季
抹茶落季 2021-01-31 05:59

Given a templated function declared like this:

template
int Function(T object);

A user can invoke this function by specifying th

2条回答
  •  误落风尘
    2021-01-31 06:19

    In C++17, you can have auto non-type template parameters. This will let you solve your problem.

    Something like:

    template>
    int Function();
    

    (assuming you want the type T within the body of Function)

    In C++14, the C++17 feature is missing. It was added exactly because it was missing. Workarounds involve macros like #define UGLY_HACK(...) decltype(__VA_ARGS__), __VA_ARGS__.

提交回复
热议问题