c++ pimpl idiom : Implementation depending on a template parameter

前端 未结 1 492
野趣味
野趣味 2021-01-16 20:27

In this question I unsuccessfully asked how to use different pimpl implementation depending on a template argument.

Maybe this example ilustrates better what I am tr

1条回答
  •  北海茫月
    2021-01-16 21:11

    What you're trying to do is not allowed by the language.

    § 14.7.3.16 (FCD 2010-03-26) states:

    In an explicit specialization declaration for a member of a class template or a member template that appears in namespace scope, the member template and some of its enclosing class templates may remain unspecialized, except that the declaration shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized as well. In such explicit specialization declaration, the keyword template followed by a template-parameter-list shall be provided instead of the template<> preceding the explicit specialization declaration of the member. The types of the template-parameters in the template-parameter-list shall be the same as those specified in the primary template definition.

    [ Example:
    template  class A {
        template class B {
            template void mf1(T3);
            void mf2();
        };
    };
    template <> template 
    
    class A::B {
        template  void mf1(T);
    };
    template <> template <> template
    void A::B::mf1(T t) { }
    template  template <>
    void A::B::mf2() { } // ill-formed; B is specialized but
    // its enclosing class template A is not
    —end example ]
    

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