Skip to content

Instantly share code, notes, and snippets.

@zhangyuchi
Created January 25, 2016 10:13
Show Gist options
  • Select an option

  • Save zhangyuchi/de37c56782c619ca47fb to your computer and use it in GitHub Desktop.

Select an option

Save zhangyuchi/de37c56782c619ca47fb to your computer and use it in GitHub Desktop.
c++11 variadic templates exsample
#include <iostream>
using namespace std;
void f()
{
cout<<"0 args"<<endl;
}
void f(int a)
{
cout<<"1 args"<<endl;
}
void f(int a, int b)
{
cout<<"2 args"<<endl;
}
void f(int a, int b, int c)
{
cout<<"3 args"<<endl;
}
template <int... N>
struct call_impl
{
static void call()
{
f(N...);
}
};
int main()
{
call_impl<1,2,3,4>::call();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment