mercredi 13 juillet 2016

Accept Template of Child Class as Template for Object

In the bellow example, using the std::chrono library, I am looking for a means to accept a type of duration for a basic timer.

template <std::chrono::duration D> //Accept either std::chrono::minute, second, etc...
class myTimer{


}

However, this will not work as Duration doesn't match the criteria of the template keyword.

template <class T>
class myTimer{

   //I could do a static cast, but Duration is only a template used by the children, not an actual class per say. 

}

So my question boils down to, what would the best solution be for less code and better usability? I feel like a static cast with a unknown child from a template wouldn't work well, but I may be completely wrong.

Aucun commentaire:

Enregistrer un commentaire