Template alias, Template specialization and Template Template parameters
Asked Answered
A

1

10

I want to determine the underlying template of a template parameter by using a combination of a template alias and template specializations. The follwing code compiles fine on gcc 4.8, 6.2.1 but not on 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;
}

Which behavior is standard conformant?

Aestivation answered 12/9, 2016 at 20:48 Comment(4)
This is an active core issue.Mountaineer
@t.c. that looks different, matching templates not template instances?Tomikotomkiel
@Yakk It's the same; the issue is matching Resolution<First<int>, int>::type (which despite the name is a template) against First in the Foo<First, T> partial specialization.Mountaineer
@Mountaineer thx for the clarification. Any idea when there will be a final desicion on this matter?Aestivation
W
1

Answer: This is a know bug in the C++ Standard Core Language , as described by T.C. in the comments . http://wg21.link/cwg1286

Wernher answered 9/9, 2017 at 6:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.