mercredi 11 septembre 2019

Is it possible to pass a type and a pointer of that type to a c++ template class using a single parameter of a template class?

Is it possible to pass a type and a pointer of that type to a c++ template class using a single parameter of a template class?


I want to take a pointer to a embedded hardware address (an uart) which has the type UART_HandleTypeDef and deduce that type information instead of manually declaring it. Something akin to:

template<typename T> class serial{
public:
    T::value_type* uart = T;
};

I want to get away from the normal notation which would require me to state the type and then pass a pointer:

template<typename T,T* ptr> class c{
public:
  T* _ptr = ptr;
};

update: I forgot to mention: pre C++11 is supported by my compiler. It supports some C++11 features

Aucun commentaire:

Enregistrer un commentaire