]> git.tdb.fi Git - libs/core.git/blob - source/io/print.h
Use variadic templates for format and print functions if available
[libs/core.git] / source / io / print.h
1 #ifndef MSP_IO_PRINT_H_
2 #define MSP_IO_PRINT_H_
3
4 #include <msp/strings/format.h>
5 #include "base.h"
6 #include "console.h"
7
8 namespace Msp {
9 namespace IO {
10
11 /**
12 Writes a string to an I/O object.  Same as o.write(f).  Provided for
13 completeness with the other print functions.
14 */
15 inline unsigned print(Base &o, const std::string &f)
16 { return o.write(f); }
17
18 #if __cplusplus>=201103L
19 template<typename... Args>
20 inline unsigned print(Base &o, const std::string &f, Args... args)
21 { return print(o, format(f, args...)); }
22
23 #else
24 template<typename A1>
25 inline unsigned print(Base &o, const std::string &f, A1 a1)
26 { return print(o, format(f, a1)); }
27
28 template<typename A1, typename A2>
29 inline unsigned print(Base &o, const std::string &f, A1 a1, A2 a2)
30 { return print(o, format(f, a1, a2)); }
31
32 template<typename A1, typename A2, typename A3>
33 inline unsigned print(Base &o, const std::string &f, A1 a1, A2 a2, A3 a3)
34 { return print(o, format(f, a1, a2, a3)); }
35
36 template<typename A1, typename A2, typename A3, typename A4>
37 inline unsigned print(Base &o, const std::string &f, A1 a1, A2 a2, A3 a3, A4 a4)
38 { return print(o, format(f, a1, a2, a3, a4)); }
39
40 template<typename A1, typename A2, typename A3, typename A4, typename A5>
41 inline unsigned print(Base &o, const std::string &f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
42 { return print(o, format(f, a1, a2, a3, a4, a5)); }
43 #endif
44
45 /* The following functions print to console */
46
47 inline unsigned print(const std::string &f)
48 { return print(cout, f); }
49
50 #if __cplusplus>=201103L
51 template<typename... Args>
52 inline unsigned print(const std::string &f, Args... args)
53 { return print(cout, f, args...); }
54
55 #else
56 template<typename A1>
57 inline unsigned print(const std::string &f, A1 a1)
58 { return print(cout, f, a1); }
59
60 template<typename A1, typename A2>
61 inline unsigned print(const std::string &f, A1 a1, A2 a2)
62 { return print(cout, f, a1, a2); }
63
64 template<typename A1, typename A2, typename A3>
65 inline unsigned print(const std::string &f, A1 a1, A2 a2, A3 a3)
66 { return print(cout, f, a1, a2, a3); }
67
68 template<typename A1, typename A2, typename A3, typename A4>
69 inline unsigned print(const std::string &f, A1 a1, A2 a2, A3 a3, A4 a4)
70 { return print(cout, f, a1, a2, a3, a4); }
71
72 template<typename A1, typename A2, typename A3, typename A4, typename A5>
73 inline unsigned print(const std::string &f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
74 { return print(cout, f, a1, a2, a3, a4, a5); }
75 #endif
76
77 } // namespace IO
78 } // namespace Msp
79
80 #endif