Created
January 25, 2016 10:13
-
-
Save zhangyuchi/de37c56782c619ca47fb to your computer and use it in GitHub Desktop.
c++11 variadic templates exsample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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