diff --git a/ch16/ex16_52_variadic_template.cpp b/ch16/ex16_52_variadic_template.cpp new file mode 100644 index 00000000..e53708c4 --- /dev/null +++ b/ch16/ex16_52_variadic_template.cpp @@ -0,0 +1,28 @@ +#include +#include + +using std::string; +using std::cout; +using std::endl; + +template +void foo(const T & t, const Args& ... rest) +{ + cout << "sizeof...(Args): " << sizeof...(Args) << endl; + cout << "sizeof...(rest): " << sizeof...(rest) << endl; +} + +int main() +{ + int i = 0; + double d = 3.14; + string s = "how now brown cow"; + cout << "foo(i, s, 42, d) : " << endl; + foo(i, s, 42, d); + cout << "foo(s, 42, \"hi\") : " << endl; + foo(s, 42, "hi"); + cout << "foo(d, s) : " << endl; + foo(d, s); + cout << "foo(\"hi\") : " << endl; + foo("hi"); +}