dimanche 6 décembre 2015

How to pass constexpr as a template parameter?

I have a templated class MyClass and I want to run it for various parameters in order to measure some values. I know the exact parameters before the compilation hence I assume there must be a way of achieving the goal.

My code so far:

template <int T>
class MyClass { /*...*/ };


constexpr int PARAMS[] = {1,2,3 /*, ...*/};
for (constexpr auto& t: PARAMS) {
    MyClass<t> myClass;
    // ... do sth
}

However the compiler (gcc v4.9.2, C++11) doesn't accept that. I also tried using const instead of constexpr which doesn't work as well.

Is it possible to something like this? I really don't want to use macros at all.

Aucun commentaire:

Enregistrer un commentaire