Reputation: 2938
I need to represent a hierarchy like this:
template<typename T>
struct X
{
};
template<typename Derived = void>
struct Y : Y<void>
{
//Note: not trying to use SFINAE here
using DerivedType = typename std::enable_if<std::is_base_of<Y, Derived>::value, Derived>::type;
};
template<>
struct Y<void> : X<Y<void>>
{
};
struct Z : Y<Z>
{
};
Both Z and Y<void> need to be instantiable:
W<Y<>> wy;
W<Z> wz;
All Y<T> need to be instances of Y<void>, and if possible I would prefer not to have two different names to make it work. (That is my last resort)
The problem is, I don't know how to make this work. The above code obviously doesn't work as intended and doesn't compile. Is there a way I can make it work, or do you have any recommendations for alternatives besides the one I already mentioned?
Upvotes: 0
Views: 120
Reputation: 477040
How about reordering it:
template <typename> struct Y;
template <> struct Y<void> : X<Y<void>> { };
template <typename T = void> struct Y : Y<void> { };
Upvotes: 3