dimanche 26 mai 2019

How to access params in variadic template function

The old way to make variadic function in C/C++ is using va_list, va_start, va_arg, va_end defined in cstdarg. C++11 comes with variadic function template syntax, but how to access the values?

//example
#include <iostream>
using namespace std;

template <typename... types>
void print(types... Params){
  //this is not working:
  cout <<Params[0] <<endl;
  cout <<Params[1] <<endl;
}

int main(){
  print(123, 456);
}

Aucun commentaire:

Enregistrer un commentaire