c++templates

Template specialization inside a template class using class template parameters


template<typename TypA, typename TypX>
struct MyClass {
    using TypAlias = TypA<TypX>; // error: ‘TypA’ is not a template [-Wtemplate-body]
};

MyClass is very often specialized like MyClass<A<X>,X> so I wanted to make a shortcut to this specialization. But I can't get rid of that compile error...


Solution

  • A template-template parameter solves this.

    template<template<class> class TypA, typename TypX>
    struct MyClass {
      using TypeAlias = TypA<TypX>;
    };