Talk #3188 » ex2_variadic.cpp
1 |
/*
|
---|---|
2 |
* Created: 26-01-2016
|
3 |
* Modified: Wed 27 Jan 2016 17:54:46 CET
|
4 |
* Author: Jonas R. Glesaaen (jonas@glesaaen.com)
|
5 |
*/
|
6 |
|
7 |
#include<iostream>
|
8 |
#include<boost/type_index.hpp>
|
9 |
|
10 |
using boost::typeindex::type_id_with_cvr; |
11 |
|
12 |
//End of recursion for "print line" function
|
13 |
void println(std::ostream & os) |
14 |
{
|
15 |
os << std::endl; |
16 |
}
|
17 |
|
18 |
//Generic print line function that can take any number of arguments of any type
|
19 |
template <typename Head, typename... Tail> |
20 |
void println(std::ostream & os, const Head & head, Tail... tail) |
21 |
{
|
22 |
//Uncomment to see types
|
23 |
//std::cout << "T: "
|
24 |
//<< type_id_with_cvr<Head>().pretty_name() << ",\t"
|
25 |
//<< "x: "
|
26 |
//<< type_id_with_cvr<decltype(head)>().pretty_name() << "\n";
|
27 |
|
28 |
//os << head;
|
29 |
//if( sizeof...(tail) != 0)
|
30 |
//os << ", ";
|
31 |
|
32 |
println(os,tail...); |
33 |
}
|
34 |
|
35 |
int main(int, char**) |
36 |
{
|
37 |
println(std::cout, 7, 8.43, 'c', "Hello"); |
38 |
|
39 |
}
|