jeudi 17 juin 2021

Get number of template parameters with template template function

I'm not sure if this is possible, but I would like to count the number of template arguments of any class like:

template <typename T>
class MyTemplateClass { ... };

template <typename T, typename U>
class MyTemplateClass2 { ... };

such that template_size<MyTemplateClass>() == 1 and template_size<MyTemplateClass2>() == 2. I'm a beginner to template templates, so I came up with this function which of course does not work:

template <template <typename... Ts> class T>
constexpr size_t template_size() {
     return sizeof...(Ts);
}

because Ts can not be referenced. I also know that it might come to problems when handling variantic templates, but that is not the case, at least for my application.

Thx in advance

Aucun commentaire:

Enregistrer un commentaire