-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplates2.cpp
More file actions
56 lines (47 loc) · 1.35 KB
/
Templates2.cpp
File metadata and controls
56 lines (47 loc) · 1.35 KB
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
/**
* \file Templates2.cpp
* \brief
*
* \todo
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
// Called at last
// Function that accepts no parameter.
// It is to break the recursion chain of vardiac template function
void
log(const char *a_format)
{
STD_UNUSED(a_format)
std::cout << "[" << __FUNCTION__ << "]: no params" << std::endl;
}
//-------------------------------------------------------------------------------------------------
// Variadic Template Function that accepts variable number of arguments of any type
template<typename T, typename ... Params>
void
log(
const char *a_format,
const T &a_value,
const Params & ... a_params
)
{
// Print the First Element
std::cout << "[" << __FUNCTION__ << "]: " << a_value << std::endl;
// Forward the remaining arguments
log(a_format, a_params...);
}
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
log("{}-{}-{}", 2, 3.4, "aaa");
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
__FUNCTION__: log, a_value: 2
__FUNCTION__: log, a_value: 3.4
__FUNCTION__: log, a_value: aaa
__FUNCTION__: log
#endif