vendredi 27 décembre 2019

Is an initializer list static enough to allow instantiating templates?

I apologize for the badly formed question. I wasn't sure how to ask it.

#include <iostream>

template <int V>
void output() {
  std::cout << V << "\n";
}

int main() {

  output<1>(); // this works
  output<2>();

  for (int v : {1,2,3} ) {
    output<v>(); // this not
  }
  return 0;
}

I thought having a finite number of iterations would be enough to make that templated function instantiated, but no.

Is there a way to get this to work?

Aucun commentaire:

Enregistrer un commentaire