Skip to content

Instantly share code, notes, and snippets.

@kantoniak
Created February 27, 2017 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kantoniak/ebc3aff5ed33ea941ac460afcc63bb18 to your computer and use it in GitHub Desktop.
Save kantoniak/ebc3aff5ed33ea941ac460afcc63bb18 to your computer and use it in GitHub Desktop.
Variadic templates example: sizeof for parameter pack
#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