Tuesday, October 3, 2017

C++14: std::integer_sequence

C++14 added integer_sequence template class

#include <iostream>
#include <vector>
#include <utility>

void myPrintFunction(int a, int b, int c, int d)
{
std::cout << a << " " << b << " " << c << " " << d << std::endl;
}

template<typename T, T... Sequence>
void myTemplateFunction(std::integer_sequence<T, Sequence...>)
{
  myPrintFunction(Sequence...);
}

int main()
{
  std::integer_sequence<int, 2, 4, 6, 8> mySequence;
 
  myTemplateFunction(mySequence);

  return 0;
}
// Output: 2 4 6 8
Reference: https://cpprefjp.github.io/reference/utility/integer_sequence.html

No comments:

Post a Comment