c++c++11template-specializationtemplate-aliases

Can I specialize a class template with an alias template?


Here's a simple example:

class bar {};

template <typename>
class foo {};

template <>
using foo<int> = bar;

Is this allowed?


Solution

  • $ clang++ -std=c++0x test.cpp
    test.cpp:6:1: error: explicit specialization of alias templates is not permitted
    template <>
    ^~~~~~~~~~~
    1 error generated.
    

    Reference: 14.1 [temp.decls]/p3:

    3 Because an alias-declaration cannot declare a template-id, it is not possible to partially or explicitly specialize an alias template.