Skip to content

Commit 2d61139

Browse files
authored
Merge pull request #2250 from joto/contrib-fmt
Update included fmt library to version 11.0.2
2 parents 56e204f + e23dab3 commit 2d61139

File tree

20 files changed

+5490
-4792
lines changed

20 files changed

+5490
-4792
lines changed

contrib/fmt/README.contrib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Source: https://github.com/fmtlib/fmt
2-
Revision: v10.2.1
2+
Revision: v11.0.2

contrib/fmt/README.md

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ that help victims of the war in Ukraine: <https://www.stopputin.net/>.
2020
Q&A: ask questions on [StackOverflow with the tag
2121
fmt](https://stackoverflow.com/questions/tagged/fmt).
2222

23-
Try {fmt} in [Compiler Explorer](https://godbolt.org/z/Eq5763).
23+
Try {fmt} in [Compiler Explorer](https://godbolt.org/z/8Mx1EW73v).
2424

2525
# Features
2626

27-
- Simple [format API](https://fmt.dev/latest/api.html) with positional
27+
- Simple [format API](https://fmt.dev/latest/api/) with positional
2828
arguments for localization
2929
- Implementation of [C++20
3030
std::format](https://en.cppreference.com/w/cpp/utility/format) and
3131
[C++23 std::print](https://en.cppreference.com/w/cpp/io/print)
32-
- [Format string syntax](https://fmt.dev/latest/syntax.html) similar
32+
- [Format string syntax](https://fmt.dev/latest/syntax/) similar
3333
to Python\'s
3434
[format](https://docs.python.org/3/library/stdtypes.html#str.format)
3535
- Fast IEEE 754 floating-point formatter with correct rounding,
3636
shortness and round-trip guarantees using the
3737
[Dragonbox](https://github.com/jk-jeon/dragonbox) algorithm
3838
- Portable Unicode support
3939
- Safe [printf
40-
implementation](https://fmt.dev/latest/api.html#printf-formatting)
40+
implementation](https://fmt.dev/latest/api/#printf-formatting)
4141
including the POSIX extension for positional arguments
4242
- Extensibility: [support for user-defined
43-
types](https://fmt.dev/latest/api.html#formatting-user-defined-types)
43+
types](https://fmt.dev/latest/api/#formatting-user-defined-types)
4444
- High performance: faster than common standard library
4545
implementations of `(s)printf`, iostreams, `to_string` and
4646
`to_chars`, see [Speed tests](#speed-tests) and [Converting a
@@ -58,8 +58,8 @@ Try {fmt} in [Compiler Explorer](https://godbolt.org/z/Eq5763).
5858
buffer overflow errors
5959
- Ease of use: small self-contained code base, no external
6060
dependencies, permissive MIT
61-
[license](https://github.com/fmtlib/fmt/blob/master/LICENSE.rst)
62-
- [Portability](https://fmt.dev/latest/index.html#portability) with
61+
[license](https://github.com/fmtlib/fmt/blob/master/LICENSE)
62+
- [Portability](https://fmt.dev/latest/#portability) with
6363
consistent output across platforms and support for older compilers
6464
- Clean warning-free codebase even on high warning levels such as
6565
`-Wall -Wextra -pedantic`
@@ -203,43 +203,38 @@ and [ryu](https://github.com/ulfjack/ryu):
203203

204204
## Compile time and code bloat
205205

206-
The script
207-
[bloat-test.py](https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py)
208-
from [format-benchmark](https://github.com/fmtlib/format-benchmark)
209-
tests compile time and code bloat for nontrivial projects. It generates
210-
100 translation units and uses `printf()` or its alternative five times
211-
in each to simulate a medium-sized project. The resulting executable
212-
size and compile time (Apple LLVM version 8.1.0 (clang-802.0.42), macOS
213-
Sierra, best of three) is shown in the following tables.
206+
The script [bloat-test.py][test] from [format-benchmark][bench] tests compile
207+
time and code bloat for nontrivial projects. It generates 100 translation units
208+
and uses `printf()` or its alternative five times in each to simulate a
209+
medium-sized project. The resulting executable size and compile time (Apple
210+
clang version 15.0.0 (clang-1500.1.0.2.5), macOS Sonoma, best of three) is shown
211+
in the following tables.
212+
213+
[test]: https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py
214+
[bench]: https://github.com/fmtlib/format-benchmark
214215

215216
**Optimized build (-O3)**
216217

217218
| Method | Compile Time, s | Executable size, KiB | Stripped size, KiB |
218219
|---------------|-----------------|----------------------|--------------------|
219-
| printf | 2.6 | 29 | 26 |
220-
| printf+string | 16.4 | 29 | 26 |
221-
| iostreams | 31.1 | 59 | 55 |
222-
| {fmt} | 19.0 | 37 | 34 |
223-
| Boost Format | 91.9 | 226 | 203 |
224-
| Folly Format | 115.7 | 101 | 88 |
225-
226-
As you can see, {fmt} has 60% less overhead in terms of resulting binary
227-
code size compared to iostreams and comes pretty close to `printf`.
228-
Boost Format and Folly Format have the largest overheads.
220+
| printf | 1.6 | 54 | 50 |
221+
| IOStreams | 25.9 | 98 | 84 |
222+
| fmt 83652df | 4.8 | 54 | 50 |
223+
| tinyformat | 29.1 | 161 | 136 |
224+
| Boost Format | 55.0 | 530 | 317 |
229225

230-
`printf+string` is the same as `printf` but with an extra `<string>`
231-
include to measure the overhead of the latter.
226+
{fmt} is fast to compile and is comparable to `printf` in terms of per-call
227+
binary size (within a rounding error on this system).
232228

233229
**Non-optimized build**
234230

235231
| Method | Compile Time, s | Executable size, KiB | Stripped size, KiB |
236232
|---------------|-----------------|----------------------|--------------------|
237-
| printf | 2.2 | 33 | 30 |
238-
| printf+string | 16.0 | 33 | 30 |
239-
| iostreams | 28.3 | 56 | 52 |
240-
| {fmt} | 18.2 | 59 | 50 |
241-
| Boost Format | 54.1 | 365 | 303 |
242-
| Folly Format | 79.9 | 445 | 430 |
233+
| printf | 1.4 | 54 | 50 |
234+
| IOStreams | 23.4 | 92 | 68 |
235+
| {fmt} 83652df | 4.4 | 89 | 85 |
236+
| tinyformat | 24.5 | 204 | 161 |
237+
| Boost Format | 36.4 | 831 | 462 |
243238

244239
`libc`, `lib(std)c++`, and `libfmt` are all linked as shared libraries
245240
to compare formatting function overhead only. Boost Format is a
@@ -248,7 +243,7 @@ header-only library so it doesn\'t provide any linkage options.
248243
## Running the tests
249244

250245
Please refer to [Building the
251-
library](https://fmt.dev/latest/usage.html#building-the-library) for
246+
library](https://fmt.dev/latest/get-started/#building-from-source) for
252247
instructions on how to build the library and run the unit tests.
253248

254249
Benchmarks reside in a separate repository,
@@ -270,8 +265,7 @@ or the bloat test:
270265

271266
# Migrating code
272267

273-
[clang-tidy](https://clang.llvm.org/extra/clang-tidy/) v17 (not yet
274-
released) provides the
268+
[clang-tidy](https://clang.llvm.org/extra/clang-tidy/) v18 provides the
275269
[modernize-use-std-print](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-print.html)
276270
check that is capable of converting occurrences of `printf` and
277271
`fprintf` to `fmt::print` if configured to do so. (By default it
@@ -303,7 +297,7 @@ converts to `std::print`.)
303297
underwater vehicle
304298
- [Drake](https://drake.mit.edu/): a planning, control, and analysis
305299
toolbox for nonlinear dynamical systems (MIT)
306-
- [Envoy](https://lyft.github.io/envoy/): C++ L7 proxy and
300+
- [Envoy](https://github.com/envoyproxy/envoy): C++ L7 proxy and
307301
communication bus (Lyft)
308302
- [FiveM](https://fivem.net/): a modification framework for GTA V
309303
- [fmtlog](https://github.com/MengRao/fmtlog): a performant
@@ -343,7 +337,7 @@ converts to `std::print`.)
343337
- [Quill](https://github.com/odygrd/quill): asynchronous low-latency
344338
logging library
345339
- [QKW](https://github.com/ravijanjam/qkw): generalizing aliasing to
346-
simplify navigation, and executing complex multi-line terminal
340+
simplify navigation, and execute complex multi-line terminal
347341
command sequences
348342
- [redis-cerberus](https://github.com/HunanTV/redis-cerberus): a Redis
349343
cluster proxy
@@ -432,7 +426,7 @@ code bloat issues (see [Benchmarks](#benchmarks)).
432426
433427
## FastFormat
434428
435-
This is an interesting library that is fast, safe, and has positional
429+
This is an interesting library that is fast, safe and has positional
436430
arguments. However, it has significant limitations, citing its author:
437431
438432
> Three features that have no hope of being accommodated within the
@@ -442,8 +436,8 @@ arguments. However, it has significant limitations, citing its author:
442436
> - Octal/hexadecimal encoding
443437
> - Runtime width/alignment specification
444438
445-
It is also quite big and has a heavy dependency, STLSoft, which might be
446-
too restrictive for using it in some projects.
439+
It is also quite big and has a heavy dependency, on STLSoft, which might be
440+
too restrictive for use in some projects.
447441
448442
## Boost Spirit.Karma
449443
@@ -462,7 +456,7 @@ second](http://www.zverovich.net/2020/06/13/fast-int-to-string-revisited.html).
462456
463457
# Documentation License
464458
465-
The [Format String Syntax](https://fmt.dev/latest/syntax.html) section
459+
The [Format String Syntax](https://fmt.dev/latest/syntax/) section
466460
in the documentation is based on the one from Python [string module
467461
documentation](https://docs.python.org/3/library/string.html#module-string).
468462
For this reason, the documentation is distributed under the Python
@@ -486,5 +480,5 @@ To report a security issue, please disclose it at [security
486480
advisory](https://github.com/fmtlib/fmt/security/advisories/new).
487481
488482
This project is maintained by a team of volunteers on a
489-
reasonable-effort basis. As such, please give us at least 90 days to
483+
reasonable-effort basis. As such, please give us at least *90* days to
490484
work on a fix before public exposure.

contrib/fmt/include/fmt/args.h

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
#ifndef FMT_ARGS_H_
99
#define FMT_ARGS_H_
1010

11-
#include <functional> // std::reference_wrapper
12-
#include <memory> // std::unique_ptr
13-
#include <vector>
11+
#ifndef FMT_MODULE
12+
# include <functional> // std::reference_wrapper
13+
# include <memory> // std::unique_ptr
14+
# include <vector>
15+
#endif
1416

15-
#include "core.h"
17+
#include "format.h" // std_string_view
1618

1719
FMT_BEGIN_NAMESPACE
1820

@@ -28,15 +30,18 @@ auto unwrap(const std::reference_wrapper<T>& v) -> const T& {
2830
return static_cast<const T&>(v);
2931
}
3032

31-
class dynamic_arg_list {
32-
// Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
33-
// templates it doesn't complain about inability to deduce single translation
34-
// unit for placing vtable. So storage_node_base is made a fake template.
35-
template <typename = void> struct node {
36-
virtual ~node() = default;
37-
std::unique_ptr<node<>> next;
38-
};
33+
// node is defined outside dynamic_arg_list to workaround a C2504 bug in MSVC
34+
// 2022 (v17.10.0).
35+
//
36+
// Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
37+
// templates it doesn't complain about inability to deduce single translation
38+
// unit for placing vtable. So node is made a fake template.
39+
template <typename = void> struct node {
40+
virtual ~node() = default;
41+
std::unique_ptr<node<>> next;
42+
};
3943

44+
class dynamic_arg_list {
4045
template <typename T> struct typed_node : node<> {
4146
T value;
4247

@@ -62,14 +67,10 @@ class dynamic_arg_list {
6267
} // namespace detail
6368

6469
/**
65-
\rst
66-
A dynamic version of `fmt::format_arg_store`.
67-
It's equipped with a storage to potentially temporary objects which lifetimes
68-
could be shorter than the format arguments object.
69-
70-
It can be implicitly converted into `~fmt::basic_format_args` for passing
71-
into type-erased formatting functions such as `~fmt::vformat`.
72-
\endrst
70+
* A dynamic list of formatting arguments with storage.
71+
*
72+
* It can be implicitly converted into `fmt::basic_format_args` for passing
73+
* into type-erased formatting functions such as `fmt::vformat`.
7374
*/
7475
template <typename Context>
7576
class dynamic_format_arg_store
@@ -147,22 +148,20 @@ class dynamic_format_arg_store
147148
constexpr dynamic_format_arg_store() = default;
148149

149150
/**
150-
\rst
151-
Adds an argument into the dynamic store for later passing to a formatting
152-
function.
153-
154-
Note that custom types and string types (but not string views) are copied
155-
into the store dynamically allocating memory if necessary.
156-
157-
**Example**::
158-
159-
fmt::dynamic_format_arg_store<fmt::format_context> store;
160-
store.push_back(42);
161-
store.push_back("abc");
162-
store.push_back(1.5f);
163-
std::string result = fmt::vformat("{} and {} and {}", store);
164-
\endrst
165-
*/
151+
* Adds an argument into the dynamic store for later passing to a formatting
152+
* function.
153+
*
154+
* Note that custom types and string types (but not string views) are copied
155+
* into the store dynamically allocating memory if necessary.
156+
*
157+
* **Example**:
158+
*
159+
* fmt::dynamic_format_arg_store<fmt::format_context> store;
160+
* store.push_back(42);
161+
* store.push_back("abc");
162+
* store.push_back(1.5f);
163+
* std::string result = fmt::vformat("{} and {} and {}", store);
164+
*/
166165
template <typename T> void push_back(const T& arg) {
167166
if (detail::const_check(need_copy<T>::value))
168167
emplace_arg(dynamic_args_.push<stored_type<T>>(arg));
@@ -171,20 +170,18 @@ class dynamic_format_arg_store
171170
}
172171

173172
/**
174-
\rst
175-
Adds a reference to the argument into the dynamic store for later passing to
176-
a formatting function.
177-
178-
**Example**::
179-
180-
fmt::dynamic_format_arg_store<fmt::format_context> store;
181-
char band[] = "Rolling Stones";
182-
store.push_back(std::cref(band));
183-
band[9] = 'c'; // Changing str affects the output.
184-
std::string result = fmt::vformat("{}", store);
185-
// result == "Rolling Scones"
186-
\endrst
187-
*/
173+
* Adds a reference to the argument into the dynamic store for later passing
174+
* to a formatting function.
175+
*
176+
* **Example**:
177+
*
178+
* fmt::dynamic_format_arg_store<fmt::format_context> store;
179+
* char band[] = "Rolling Stones";
180+
* store.push_back(std::cref(band));
181+
* band[9] = 'c'; // Changing str affects the output.
182+
* std::string result = fmt::vformat("{}", store);
183+
* // result == "Rolling Scones"
184+
*/
188185
template <typename T> void push_back(std::reference_wrapper<T> arg) {
189186
static_assert(
190187
need_copy<T>::value,
@@ -193,10 +190,10 @@ class dynamic_format_arg_store
193190
}
194191

195192
/**
196-
Adds named argument into the dynamic store for later passing to a formatting
197-
function. ``std::reference_wrapper`` is supported to avoid copying of the
198-
argument. The name is always copied into the store.
199-
*/
193+
* Adds named argument into the dynamic store for later passing to a
194+
* formatting function. `std::reference_wrapper` is supported to avoid
195+
* copying of the argument. The name is always copied into the store.
196+
*/
200197
template <typename T>
201198
void push_back(const detail::named_arg<char_type, T>& arg) {
202199
const char_type* arg_name =
@@ -209,19 +206,15 @@ class dynamic_format_arg_store
209206
}
210207
}
211208

212-
/** Erase all elements from the store */
209+
/// Erase all elements from the store.
213210
void clear() {
214211
data_.clear();
215212
named_info_.clear();
216213
dynamic_args_ = detail::dynamic_arg_list();
217214
}
218215

219-
/**
220-
\rst
221-
Reserves space to store at least *new_cap* arguments including
222-
*new_cap_named* named arguments.
223-
\endrst
224-
*/
216+
/// Reserves space to store at least `new_cap` arguments including
217+
/// `new_cap_named` named arguments.
225218
void reserve(size_t new_cap, size_t new_cap_named) {
226219
FMT_ASSERT(new_cap >= new_cap_named,
227220
"Set of arguments includes set of named arguments");

0 commit comments

Comments
 (0)