It's not possible with that for loop. The reason is simple: n[i] inside the loop is not a constant expression. i could change inside the loop in different ways and the information about whether to instantiate a specific instance of SomeClass or some other is runtime-dependent.
You can use template meta programming instead:
template <int from, int to>
struct for_ {
template<template<int> class Fn>
static void run() {
Fn<from>::run();
for_<from + 1, to>::template run<Fn>();
}
};
template <int to>
struct for_<to, to> {
template<template<int> class Fn>
static void run() {}
};
We can then define our own utilities:
template <int n>
struct SomeClass {};
constexpr int n[5] = { 4, 8, 16, 32, 64 };
template<int i>
struct functor {
static void run() {
SomeClass<n[i]> c;
// something else
}
};
and use it as:
int main() {
for_<0, 5>::run<functor>();
return 0;
}
Live demo