Extract C++ template parameters

前端 未结 5 1788
轻奢々
轻奢々 2020-12-05 13:26

Although I\'m doubtful, I\'m curious as to whether it\'s possible to extract primitive-type template parameters from an existing type, perhaps using RTTI.

For exampl

5条回答
  •  心在旅途
    2020-12-05 13:46

    You can easily do this in C++11 using argument deduction and unevaluated contexts (note that demo uses C++14's variable template feature for convenience).

    #include 
    #include 
    
    template
    struct foo {};
    
    template
    struct val {
        static constexpr auto N = arg_N;
    };
    
    template