1
1
## An {fmt} v7 or earlier wrapper around OutputDebugString
2
2
3
- This makes sending formatted message much more plesant.
3
+ This makes sending formatted message much more plesant and works on almost _ any _ compiler, even with just C++11 .
4
4
5
- see: https://godbolt.org/z/e7KraEM73
5
+ see: https://godbolt.org/z/ab68shhfP
6
6
7
- Notice the example uses gcc to demonstrate because the mscv {fmt} is fixed at some higher version on compiler-explorer.
8
- However the code below was checked working on vs2022.
7
+ Notice the example uses gcc4 to demonstrate because the mscv {fmt} is fixed at some higher version on compiler-explorer.
8
+ However the code below was checked working on vs2022 and gcc 4 (which is from 2014)
9
9
10
10
```
11
11
#define FMT_HEADER_ONLY
12
12
#include <fmt/format.h>
13
13
14
- #include <sstream>
15
- #include <string_view>
16
-
17
14
#include "windows.h"
18
15
19
16
template <typename... Args>
20
- void DebugMessage(std ::string_view format, Args &&... args)
17
+ void DebugMessage(fmt ::string_view format, Args &&... args)
21
18
{
22
19
auto formatted = fmt::vformat(format, fmt::make_args_checked<Args...>(format, std::forward<Args>(args)...));
23
20
OutputDebugStringA(formatted.data());
@@ -38,21 +35,19 @@ https://godbolt.org/z/49r7Ydq17
38
35
39
36
see: https://godbolt.org/z/58TxqhKWP
40
37
41
- Notice that the checks of format arguments are done at compile time by ` fmt::make_format_args `
38
+ Notice that the checks of format arguments are done at compile time by ` fmt::make_format_args ` and because of that, you need
39
+ a compiler with constexpr support.
42
40
43
41
```
44
42
#define FMT_HEADER_ONLY
45
43
#include <fmt/format.h>
46
44
47
- #include <string_view>
48
- #include <thread>
49
-
50
45
#include "windows.h"
51
46
52
47
template <typename... Args>
53
- void DebugMessage(const char* format_string , Args &&... args)
48
+ void DebugMessage(fmt::string_view format , Args &&... args)
54
49
{
55
- auto formatted = fmt::vformat(format_string , fmt::make_format_args(std::forward<Args>(args)...));
50
+ auto formatted = fmt::vformat(format , fmt::make_format_args(std::forward<Args>(args)...));
56
51
OutputDebugStringA(fmt::format("[tid {}] {}\n", ::GetCurrentThreadId(), formatted).data());
57
52
}
58
53
@@ -97,6 +92,7 @@ int main()
97
92
98
93
see: https://godbolt.org/z/b186hx5xM
99
94
95
+ If you are on an OLD compiler from before 2010, you can still do this,
100
96
this is old-school streaming, its slower and has no compile time checks.
101
97
102
98
```
0 commit comments