-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariadic.cpp
56 lines (49 loc) · 1.1 KB
/
variadic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <type_traits>
template< typename T > void print(const T& v)
{
std::cout << v << "\t\t";
if (std::is_same<T, int>::value)
{
std::cout << "\t - int";
}
else if (std::is_same<T, double>::value)
{
std::cout << "\t - double";
}
else if (std::is_same<T, char>::value)
{
std::cout << " - char";
}
else if (std::is_same<T, const char*>::value)
{
std::cout << " - const char*";
}
else
{
std::cout << " - unknown";
}
std::cout << std::endl;
}
template<
typename FIRST,
typename... REST
>
void print(const FIRST& first, const REST&... rest)
{
print(first);
print(rest...);
}
void test2()
{
print(123, 78.46, (const char*)"hello world!", std::addressof(std::cout), '\t');
/*
123 - int
78.46 - double
hello world! - const char*
7901B990 - unknown
- char
D:\projects\devnull\cpp_cmd\vs\Debug\vs.exe (process 21260) exited with code 0.
Press any key to close this window . . .
*/
}