-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplates.cpp
More file actions
61 lines (48 loc) · 1.35 KB
/
Templates.cpp
File metadata and controls
61 lines (48 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
57
58
59
60
61
/**
* \file Templates.cpp
* \brief
*
* \todo
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
void
printfV(const char* a_format)
{
while (*a_format) {
if (*a_format == '%' && *++a_format != '%')
throw std::runtime_error("invalid format string: missing arguments");
std::cout << *a_format ++;
}
}
//-------------------------------------------------------------------------------------------------
template<typename T, typename... Params>
void
printfV(
const char *a_format,
const T &a_value,
const Params &... a_params
)
{
while (*a_format) {
if (*a_format == '%' && *++a_format != '%') {
// ignore the character that follows the '%': we already know the type!
std::cout << STD_TRACE_VAR(a_value) << std::endl;
return printfV(++ a_format, a_params...);
}
std::cout << *a_format++;
}
throw std::runtime_error("extra arguments provided to printfV");
}
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
printfV("-%d-%s-%f\n", 1, "s", 0.5);
// std::cout << STD_TRACE_VAR("") << std::endl;
return 0;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
#endif