0

I have a non-type parameter template class in some header file:

template <int N1, int N2>
class A;

I want to explicitly instantiate some classes in ranges N1 = [0...K1], N2 = [0...K2], but this can result in many permutations:

template A<0,0>;
template A<0,1>;
template A<1,0>;
//...

Given a proper arrangement with a source file and header, will this compile to a static library, and is it possible to generalize the permutations?

Jonas Hjulstad
  • 395
  • 1
  • 8

1 Answers1

1

The following should instantiate all templates:

#include <utility>
template<int N1, int N2>
class A;

static constexpr int K1 = 5;
static constexpr int K2 = 7;

template<int... Ns>
void helper(A<Ns % K1, Ns / K1>...);

template<int... Ns>
auto helper2(std::integer_sequence<int, Ns...>) -> decltype(&helper<Ns...>);

template<int N>
auto helper3() -> decltype(helper2(std::make_integer_sequence<int, N>()));

using foo = decltype(helper3<K1>());

Note that this will only go to K1-1 and K2-1, so if you want the closed intervals you should add one.

I do not see a reason why this should not work as a statically linked library but I did not test it.

n314159
  • 4,990
  • 1
  • 5
  • 20