模板类模板方法参数中的模板别名不起作用

Template alias not working in argument of template class template method

本文关键字:别名 不起作用 参数 模板方法      更新时间:2023-10-16

当我声明模板类的模板方法,其参数类型由模板别名指定时,我得到一个编译错误。如果我将模板类更改为类,它就会编译。如果我用实际类型(这里是Templ<bool>)替换模板别名,它也会编译。当它是模板类参数类型是模板别名时,为什么不起作用?

编译器为gcc版本4.8.0 (Ubuntu/Linaro 4.8.0-2ubuntu2~12.04)

template <template <typename T> class Templ>
using Bool = Templ<bool>;
template <typename T>
class Foo {
private:
public:
    template<template<typename U> class Templ>
    void method(Bool<Templ> boolTempl);
};
template <typename T>
template <template <typename U> class Templ>
void Foo<T>::method(Bool<Templ> boolTempl) {
}
int main() {
    Foo<char> foo;
    return 0;
}
g++ templTest12.C -o templTest12 -std=c++11
templTest12.C: In substitution of `template<template<class T> class Templ> using Bool = Templ<bool> [with Templ = Templ]':
templTest12.C:17:6:   required from `class Foo<char>'
templTest12.C:30:12:   required from here
templTest12.C:2:25: error: `template<class U> class Templ' is not a template
 using Bool = Templ<bool>;

这似乎是gcc 4.8.0中的回归,因为gcc 4.7.2编译两个版本都没有错误。标准14.1/2明确规定

类和typename之间没有语义上的区别模板参数。