Skip to content

Commit 68bca8f

Browse files
authored
Update example_usage.md
1 parent 3cb47b3 commit 68bca8f

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

doc/example_usage.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
## An {fmt} v7 or earlier wrapper around OutputDebugString
22

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.
44

5-
see: https://godbolt.org/z/e7KraEM73
5+
see: https://godbolt.org/z/ab68shhfP
66

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)
99

1010
```
1111
#define FMT_HEADER_ONLY
1212
#include <fmt/format.h>
1313
14-
#include <sstream>
15-
#include <string_view>
16-
1714
#include "windows.h"
1815
1916
template <typename... Args>
20-
void DebugMessage(std::string_view format, Args &&... args)
17+
void DebugMessage(fmt::string_view format, Args &&... args)
2118
{
2219
auto formatted = fmt::vformat(format, fmt::make_args_checked<Args...>(format, std::forward<Args>(args)...));
2320
OutputDebugStringA(formatted.data());
@@ -38,21 +35,19 @@ https://godbolt.org/z/49r7Ydq17
3835

3936
see: https://godbolt.org/z/58TxqhKWP
4037

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.
4240

4341
```
4442
#define FMT_HEADER_ONLY
4543
#include <fmt/format.h>
4644
47-
#include <string_view>
48-
#include <thread>
49-
5045
#include "windows.h"
5146
5247
template <typename... Args>
53-
void DebugMessage(const char* format_string, Args &&... args)
48+
void DebugMessage(fmt::string_view format, Args &&... args)
5449
{
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)...));
5651
OutputDebugStringA(fmt::format("[tid {}] {}\n", ::GetCurrentThreadId(), formatted).data());
5752
}
5853
@@ -97,6 +92,7 @@ int main()
9792

9893
see: https://godbolt.org/z/b186hx5xM
9994

95+
If you are on an OLD compiler from before 2010, you can still do this,
10096
this is old-school streaming, its slower and has no compile time checks.
10197

10298
```

0 commit comments

Comments
 (0)