Unpacking arguments of a functional parameter to a C++ template class

后端 未结 1 580
小鲜肉
小鲜肉 2020-12-16 21:22

I have a question involving functional template arguments to template classes in C++.

I\'d like to define a template class Foo taking a single template

相关标签:
1条回答
  • 2020-12-16 22:23

    Declare a primary template and leave it unimplemented.

    template<typename T>
    struct foo;     // unimplemented primary template
    

    Then provide a partial specialization that matches function types as the template argument.

    template<typename Result, typename... Args>
    struct foo<Result(Args...)>
    {
        using args_t = std::tuple<Args...>;
    };
    

    You can access the nested type as

    foo<decltype(bar)>::args_t
    

    Live demo

    0 讨论(0)
提交回复
热议问题