My understanding is that in C++ user defined types are inherited and indeed this seems to be the case up to a point.
Here is what I'm trying to do but this doesn't compile:
template <typename T>
struct A{
using type = T;
};
template <typename T>
struct B: A<T>{
using type2 = type;
};
However, if I have B extend A of a non template parameter it works:
template <typename T>
struct A{
using type = T;
};
template <typename T>
struct B: A<int>{
using type2 = type;
};
Indeed, one work around I found (but which doesn't really help me for what I'm trying to do is to scope type
but this defeats the point of inheritance:
template <typename T>
struct A{
using type = T;
};
template <typename T>
struct B{
using type2 = A<T>::type;
};
Is there a proper way to achieve the behavior I want (in a more general case, this is obviously a toy example) and what are the semantics of this?
Edit: this is what I wish the code would look like, the lack of inheritance can be worked around but I wanted to understand what the limitations are
template <typename t>
struct instruction{
public:
using input = t::first;
using mem = t::second;
using newmem = mem;
using newinput = input;
using result = pair<newinput, newmem>;
};
template <typename t>
struct right_code: public instruction<t>{
using newmem = buffer<cons<mem::list2::head, mem::list1>, (std::is_same<mem::list2::tail , nil> ? cons<zero, nil>
: mem::list2::tail)>;
};
template <typename t>
using right = right_code<t>::result;
template <typename t>
struct left_code:instruction<t>{
using newmem = (std::is_same<mem::list1::tail, nil ? mem
: buffer<mem::list1::tail, cons<mem::list1::head, mem::list2>);
};
template <typename t>
using left = left_code<t>::result;