prostock
prostock

Reputation: 9545

Construct a Variadic Templated Class where arguments known at runtime

Is there a way construct an instance of a variadic templated class, where the arguments are only known at run time?

For example,

template <typename... T>
class Example {
  Example(T... args){ // some initialization}
}

int main(){

  // say i only can find out the type of class Example at run time.
  // in the below case it happens to be <int,int,char>
  example = make_unique<Example<int,int,char>>(1,2,'a');
}

Upvotes: 0

Views: 104

Answers (1)

gkhaos
gkhaos

Reputation: 705

Templates are resolved at compile time. The compiler creates functions with the necessary types. Templates are just a way for programmers to not ending in overloading functions for every possible way.

Btw the compiler exactly knows the datatypes of your example class.

Upvotes: 1

Related Questions