I'd like to write typelist methods to operate with microcontrollers GPIO's.
I'd like to create list of GPIO's and select only pins of specific port.
So, GetPinWithPort
template has specialisation which checks provided type.
template <typename... Ts>
struct tlist
{
using type = tlist;
};
template <typename T> class debug_t;
#define MAKE_PORT(NAME, ID)\
class NAME\
{\
public:\
static void Set(uint32_t v) { };\
static void Reset(uint32_t v) { };\
enum { id = ID };\
};
MAKE_PORT(Porta, 'A');
MAKE_PORT(Portb, 'B');
template <class PORT, uint8_t PIN>
class TPin
{
public:
static void Set() { PORT::Set(1 << PIN); }
static void Reset() { PORT::Reset(1 << PIN); }
typedef PORT port;
enum { pin = PIN };
};
template <class TPort, class T>
struct GetPinWithPort {
using type = tlist<>;
};
template <typename TPort, uint32_t N>
struct GetPinWithPort<TPort, TPin<TPort, N>>
{
using type = TPin<TPort, N>;
};
int main()
{
using pina = GetPinWithPort<Porta, TPin<Porta, 1> >::type;
// std::cout << typeid(pina).name() << std::endl; //Visual Studio gives: class TPin<class Porta,1>
debug_t<pina> d; //gcc output: tlist<>
}
Visual Studio gives expected result. But gcc - empty list. What is wrong here?