Equivalent of `using` aliases for `template`s

前端 未结 1 1351
执笔经年
执笔经年 2021-01-12 10:00

C++11 added alias templates such as:

 template using identity = T;
 template using EnableIf = typename std         


        
相关标签:
1条回答
  • 2021-01-12 10:43

    Best way I know to remove template is made simple warper that will do it for you:

    template<typename Meta, typename U>
    using apply = typename Meta::template Template<U>;
    

    and every where you previously used template<typename> class Template replace it with typename Meta.

    template<typename Meta>
    void do_more_stuff()
    {
        apply<Meta, int>::func(); //=== Meta::template Template<int>::func();
    }
    
    template<typename T>
    void do_stuff() {
      do_more_stuff< my_meta<T> >();
      do_more_stuff< my_meta<T> >();
    };
    
    0 讨论(0)
提交回复
热议问题