Skip to content

Commit

Permalink
Add answer for ex_16_52
Browse files Browse the repository at this point in the history
Add answer for ex_16_52
  • Loading branch information
zhqu1148980644 authored Mar 20, 2019
1 parent dfe8dbe commit 38ee803
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ch16/ex16_52_variadic_template.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <string>

using std::string;
using std::cout;
using std::endl;

template <typename T, typename ... Args>
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");
}

0 comments on commit 38ee803

Please sign in to comment.