【问题标题】:Template alias, Template specialization and Template Template parameters模板别名、模板特化和模板模板参数
【发布时间】:2017-01-20 09:05:05
【问题描述】:

我想通过结合使用模板别名和模板特化来确定模板参数的基础模板。以下代码在 gcc 4.8、6.2.1 上编译得很好,但在 clang 3.5、3.8 上编译得不好。

#include <iostream>

template <typename T> struct First {};

template <typename T> struct Second {};

template <template <typename> class F, typename T> struct Foo {};

template <typename T> struct Foo<First, T>
{
  void f() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};

template <typename T> struct Foo<Second, T> 
{
  void f() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};

template <typename F, typename T> struct Resolution {};

template <typename T> struct Resolution<First<T>, T>
{
   template <typename P> using type = First<P>;
};

template <typename T> struct Resolution<Second<T>, T>
{
    template <typename P> using type = Second<P>;
};

int main()
{
    Foo<Resolution<First<int>, int>::type, float> my_foo;
    my_foo.f(); // main.cpp:34:12: error: no member named 'f' in 'Foo<Resolution<First<int>, int>::type, float>'

    return 0;
}

哪种行为符合标准?

【问题讨论】:

  • @t.c.看起来不同,匹配的模板不是模板实例?
  • @Yakk 是一样的;问题是在Foo&lt;First, T&gt; 部分专业化中将Resolution&lt;First&lt;int&gt;, int&gt;::type(尽管名称是一个模板)与First 匹配。
  • @T.C.谢谢你的澄清。知道什么时候会对此事做出最终决定吗?

标签: c++ c++11 template-templates template-aliases


【解决方案1】:

答案:这是 C++ 标准核心语言中的一个已知错误,如 T.C. 所述。在 cmets 中。 http://wg21.link/cwg1286

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 2014-01-29
    • 2020-10-13
    • 1970-01-01
    相关资源
    最近更新 更多