specialize a member template without specializing its parent

前端 未结 4 1038
孤街浪徒
孤街浪徒 2020-12-17 20:56

I have a class template nested inside another template. Partially specializing it is easy: I just declare another template< … > block inside its parent.

4条回答
  •  悲&欢浪女
    2020-12-17 21:11

    I tend not to use nested classes too much. My main complaint is that they have a tendency to bloat the code of the class they are nested in.

    I would therefore propose another workaround:

    namespace detail
    {
      template  class BImpl;
      template  class BImpl > {};
      template  class BImpl {};
    }
    
    template 
    class A
    {
      template  struct B: BImpl {};
    };
    

    Just note that it requires to pass X as an argument to BImpl if ever you wish to also specialize A. Funny thing is that in this case, I end up with only partial specialization!

提交回复
热议问题