模板别名,模板特化和模板模板参数

时间:2016-09-12 20:48:01

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

我想通过使用模板别名和模板特化的组合来确定模板参数的基础模板。下面的代码在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;
}

哪种行为符合标准?

1 个答案:

答案 0 :(得分:1)

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

相关问题