Created
February 27, 2017 17:35
-
-
Save kantoniak/ebc3aff5ed33ea941ac460afcc63bb18 to your computer and use it in GitHub Desktop.
Variadic templates example: sizeof for parameter pack
This file contains 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 sayIt() { | |
// Does nothing | |
} | |
template <typename T, typename... Ts> | |
void sayIt(T t, Ts... ts) { | |
cout << t; | |
if (sizeof...(ts)) | |
cout << " (" << sizeof...(ts) << " more messages)"; | |
cout << endl; | |
sayIt(ts...); | |
} | |
int main() { | |
cout << "Example 3: Output" << endl; | |
sayIt("Message 1", "Message 2", "Message 3", "Message 4"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment