2

I'm implementing a pretty complex template-based functionality and I've come to an error that I can't resolve. I've simplified my case to this code:

template <typename Head, typename... T>
struct BaseIsFirst {
    using Base = Head;
};

template <typename T, typename D>
struct IAction {
    std::enable_if_t<std::is_same<T, D::Base>::value> do_action() {}
};

struct Base;
struct Derived1;
struct Derived2;
typedef BaseIsFirst<Base, Derived1, Derived2> MyBIF;

struct Base : public IAction<Base, MyBIF> { };
struct Derived1 : public Base {};
struct Derived2 : public Base {};

If I try to compile this, I get the error:

'std::is_same': 'D::Base' is not a valid template type argument for parameter '_Ty2'

I see no way to define the used types earlier. Is there a workaround for this, or is it simply not possible?

Peter Lenkefi
  • 1,306
  • 11
  • 29
  • Also, you are using `enable_if` wrong, unless you actually want it to be a hard error in the false case. – T.C. Feb 20 '17 at 16:44

1 Answers1

2

When using a type defined by a template parameter, you need to specify that it's a type. There is nothing wrong with your declaration order. Try this instead

template <typename T, typename D>
struct IAction {
    std::enable_if_t<std::is_same<T, typename D::Base>::value> do_action() {}
    //             Add typename here ^^^^^^^^
};
François Andrieux
  • 28,148
  • 6
  • 56
  • 87