Partial specialization of type parameter in template class with type & template template parameters

CodeBricks

I want to specialize the type parameter of the following template class, which has a type parameter and a template template parameter:

template <
    typename T,
    template <typename E> class Foo
> class Bar;

I tried every permutation of adding and/or omitting .template and typename in the last line of each of the following snippets, and none compiles:

1.)

template <
    template <typename E> class Foo
> class Bar<int, Foo<typename E>>;

2.)

template <
    template <typename E> class Foo
> class Bar<int, Foo.template <typename E>>;

3.)

template <
    template <typename E> class Foo
> class Bar<int, Foo<E>>;

4.)

template <
    template <typename E> class Foo
class Bar<int, Foo.template <E>>;

Why doesn't any of them work?

Regarding the last line of each applicable snippet:

  • Doesn't typename clarify E is a type used by class Foo, or can this syntax only be used within the {} body of Bar's class definition?
  • Doesn't template clarify Foo is a template and therefore prevent the compiler from parsing Foo < as Foo "is less than", or can this syntax only be used within the {} body of Bar's class definition?

How can I get this to work?

0x499602D2

Doesn't typename clarify E is a type used by class Foo, or can this syntax only be used within the {} body of Bar's class definition?

typename is only used when you are defining a type within a template definition (class could also be used) or when you are accessing a dependent type (a type that depends on a template parameter).

For more information (even about when template is used) see this thread.

How can I get this to work?

The name of a of a type within template template parameter can't actually be used. It's just there as a formality. You have to add another template parameter to your main template instead:

template <
    template<typename> class Foo,
    typename E
> class Bar<int, Foo<E>> { ... };

Moreover, if this is a specialization of the template Bar, then Bar needs a primary template to specialize:

template<typename T, typename U>
struct Bar;

template <
    template<typename> class Foo,
    typename E
> class Bar<int, Foo<E>> { ... };

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Partial template specialization for type

From Dev

Partial template specialization of a function for a type which needs additional template parameters

From Dev

Alias template, partial specialization and the invalid parameter type void

From Dev

Template method specialization for template type

From Dev

Template parameters not deducible in partial specialization

From Dev

Template specialization with type conversion

From Dev

Template specialization depending on type

From Dev

Template class partial specialization syntax

From Dev

Double partial template specialization for a class

From Dev

Template class partial specialization syntax

From Dev

Constraing template parameter by another template with any specialization type

From Dev

template specialization for template parameters

From Dev

Trying to understand partial template specialization with template template parameters

From Dev

Trying to understand partial template specialization with template template parameters

From Dev

Can a template template parameter default reference other template type parameters?

From Dev

Variadic template argument within template template parameter in a partial specialization

From Dev

Template parent class with no type parameter

From Dev

Template template partial specialization failure: "expected a class template"

From Dev

Partial template specialization for partial template parameter application not working GCC 4.8.1

From Dev

How to test if type is specialization of template with non-type parameters?

From Dev

class template specialization with template

From Dev

Partial template specialization depending on a variadic pack of integral constants of mixed type

From Dev

Using non-type template argument during partial specialization

From Dev

Invalid use of incomplete type for partial template specialization c++

From Dev

Partial template type deduction

From Dev

Partial specialization of template template parameters, with varying number of parameters

From Dev

Specialization of template type dependant structure in a template

From Dev

Function template specialization type - is it optional?

From Dev

method template specialization by return type

Related Related

  1. 1

    Partial template specialization for type

  2. 2

    Partial template specialization of a function for a type which needs additional template parameters

  3. 3

    Alias template, partial specialization and the invalid parameter type void

  4. 4

    Template method specialization for template type

  5. 5

    Template parameters not deducible in partial specialization

  6. 6

    Template specialization with type conversion

  7. 7

    Template specialization depending on type

  8. 8

    Template class partial specialization syntax

  9. 9

    Double partial template specialization for a class

  10. 10

    Template class partial specialization syntax

  11. 11

    Constraing template parameter by another template with any specialization type

  12. 12

    template specialization for template parameters

  13. 13

    Trying to understand partial template specialization with template template parameters

  14. 14

    Trying to understand partial template specialization with template template parameters

  15. 15

    Can a template template parameter default reference other template type parameters?

  16. 16

    Variadic template argument within template template parameter in a partial specialization

  17. 17

    Template parent class with no type parameter

  18. 18

    Template template partial specialization failure: "expected a class template"

  19. 19

    Partial template specialization for partial template parameter application not working GCC 4.8.1

  20. 20

    How to test if type is specialization of template with non-type parameters?

  21. 21

    class template specialization with template

  22. 22

    Partial template specialization depending on a variadic pack of integral constants of mixed type

  23. 23

    Using non-type template argument during partial specialization

  24. 24

    Invalid use of incomplete type for partial template specialization c++

  25. 25

    Partial template type deduction

  26. 26

    Partial specialization of template template parameters, with varying number of parameters

  27. 27

    Specialization of template type dependant structure in a template

  28. 28

    Function template specialization type - is it optional?

  29. 29

    method template specialization by return type

HotTag

Archive