diff --git a/contrib/fmt/README.contrib b/contrib/fmt/README.contrib
index 326599199..5284da3cf 100644
--- a/contrib/fmt/README.contrib
+++ b/contrib/fmt/README.contrib
@@ -1,2 +1,2 @@
Source: https://github.com/fmtlib/fmt
-Revision: v10.1.0
+Revision: v10.2.1
diff --git a/contrib/fmt/README.md b/contrib/fmt/README.md
new file mode 100644
index 000000000..dcfb16ec2
--- /dev/null
+++ b/contrib/fmt/README.md
@@ -0,0 +1,490 @@
+
+
+[![image](https://github.com/fmtlib/fmt/workflows/linux/badge.svg)](https://github.com/fmtlib/fmt/actions?query=workflow%3Alinux)
+[![image](https://github.com/fmtlib/fmt/workflows/macos/badge.svg)](https://github.com/fmtlib/fmt/actions?query=workflow%3Amacos)
+[![image](https://github.com/fmtlib/fmt/workflows/windows/badge.svg)](https://github.com/fmtlib/fmt/actions?query=workflow%3Awindows)
+[![fmt is continuously fuzzed at oss-fuzz](https://oss-fuzz-build-logs.storage.googleapis.com/badges/fmt.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?\%0Acolspec=ID%20Type%20Component%20Status%20Proj%20Reported%20Owner%20\%0ASummary&q=proj%3Dfmt&can=1)
+[![Ask questions at StackOverflow with the tag fmt](https://img.shields.io/badge/stackoverflow-fmt-blue.svg)](https://stackoverflow.com/questions/tagged/fmt)
+[![image](https://api.securityscorecards.dev/projects/github.com/fmtlib/fmt/badge)](https://securityscorecards.dev/viewer/?uri=github.com/fmtlib/fmt)
+
+**{fmt}** is an open-source formatting library providing a fast and safe
+alternative to C stdio and C++ iostreams.
+
+If you like this project, please consider donating to one of the funds
+that help victims of the war in Ukraine: .
+
+[Documentation](https://fmt.dev)
+
+[Cheat Sheets](https://hackingcpp.com/cpp/libs/fmt.html)
+
+Q&A: ask questions on [StackOverflow with the tag
+fmt](https://stackoverflow.com/questions/tagged/fmt).
+
+Try {fmt} in [Compiler Explorer](https://godbolt.org/z/Eq5763).
+
+# Features
+
+- Simple [format API](https://fmt.dev/latest/api.html) with positional
+ arguments for localization
+- Implementation of [C++20
+ std::format](https://en.cppreference.com/w/cpp/utility/format) and
+ [C++23 std::print](https://en.cppreference.com/w/cpp/io/print)
+- [Format string syntax](https://fmt.dev/latest/syntax.html) similar
+ to Python\'s
+ [format](https://docs.python.org/3/library/stdtypes.html#str.format)
+- Fast IEEE 754 floating-point formatter with correct rounding,
+ shortness and round-trip guarantees using the
+ [Dragonbox](https://github.com/jk-jeon/dragonbox) algorithm
+- Portable Unicode support
+- Safe [printf
+ implementation](https://fmt.dev/latest/api.html#printf-formatting)
+ including the POSIX extension for positional arguments
+- Extensibility: [support for user-defined
+ types](https://fmt.dev/latest/api.html#formatting-user-defined-types)
+- High performance: faster than common standard library
+ implementations of `(s)printf`, iostreams, `to_string` and
+ `to_chars`, see [Speed tests](#speed-tests) and [Converting a
+ hundred million integers to strings per
+ second](http://www.zverovich.net/2020/06/13/fast-int-to-string-revisited.html)
+- Small code size both in terms of source code with the minimum
+ configuration consisting of just three files, `core.h`, `format.h`
+ and `format-inl.h`, and compiled code; see [Compile time and code
+ bloat](#compile-time-and-code-bloat)
+- Reliability: the library has an extensive set of
+ [tests](https://github.com/fmtlib/fmt/tree/master/test) and is
+ [continuously fuzzed](https://bugs.chromium.org/p/oss-fuzz/issues/list?colspec=ID%20Type%20Component%20Status%20Proj%20Reported%20Owner%20Summary&q=proj%3Dfmt&can=1)
+- Safety: the library is fully type-safe, errors in format strings can
+ be reported at compile time, automatic memory management prevents
+ buffer overflow errors
+- Ease of use: small self-contained code base, no external
+ dependencies, permissive MIT
+ [license](https://github.com/fmtlib/fmt/blob/master/LICENSE.rst)
+- [Portability](https://fmt.dev/latest/index.html#portability) with
+ consistent output across platforms and support for older compilers
+- Clean warning-free codebase even on high warning levels such as
+ `-Wall -Wextra -pedantic`
+- Locale independence by default
+- Optional header-only configuration enabled with the
+ `FMT_HEADER_ONLY` macro
+
+See the [documentation](https://fmt.dev) for more details.
+
+# Examples
+
+**Print to stdout** ([run](https://godbolt.org/z/Tevcjh))
+
+``` c++
+#include
+
+int main() {
+ fmt::print("Hello, world!\n");
+}
+```
+
+**Format a string** ([run](https://godbolt.org/z/oK8h33))
+
+``` c++
+std::string s = fmt::format("The answer is {}.", 42);
+// s == "The answer is 42."
+```
+
+**Format a string using positional arguments**
+([run](https://godbolt.org/z/Yn7Txe))
+
+``` c++
+std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
+// s == "I'd rather be happy than right."
+```
+
+**Print dates and times** ([run](https://godbolt.org/z/c31ExdY3W))
+
+``` c++
+#include
+
+int main() {
+ auto now = std::chrono::system_clock::now();
+ fmt::print("Date and time: {}\n", now);
+ fmt::print("Time: {:%H:%M}\n", now);
+}
+```
+
+Output:
+
+ Date and time: 2023-12-26 19:10:31.557195597
+ Time: 19:10
+
+**Print a container** ([run](https://godbolt.org/z/MxM1YqjE7))
+
+``` c++
+#include
+#include
+
+int main() {
+ std::vector v = {1, 2, 3};
+ fmt::print("{}\n", v);
+}
+```
+
+Output:
+
+ [1, 2, 3]
+
+**Check a format string at compile time**
+
+``` c++
+std::string s = fmt::format("{:d}", "I am not a number");
+```
+
+This gives a compile-time error in C++20 because `d` is an invalid
+format specifier for a string.
+
+**Write a file from a single thread**
+
+``` c++
+#include
+
+int main() {
+ auto out = fmt::output_file("guide.txt");
+ out.print("Don't {}", "Panic");
+}
+```
+
+This can be [5 to 9 times faster than
+fprintf](http://www.zverovich.net/2020/08/04/optimal-file-buffer-size.html).
+
+**Print with colors and text styles**
+
+``` c++
+#include
+
+int main() {
+ fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,
+ "Hello, {}!\n", "world");
+ fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
+ fmt::emphasis::underline, "Olá, {}!\n", "Mundo");
+ fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
+ "你好{}!\n", "世界");
+}
+```
+
+Output on a modern terminal with Unicode support:
+
+![image](https://github.com/fmtlib/fmt/assets/%0A576385/2a93c904-d6fa-4aa6-b453-2618e1c327d7)
+
+# Benchmarks
+
+## Speed tests
+
+| Library | Method | Run Time, s |
+|-------------------|---------------|-------------|
+| libc | printf | 0.91 |
+| libc++ | std::ostream | 2.49 |
+| {fmt} 9.1 | fmt::print | 0.74 |
+| Boost Format 1.80 | boost::format | 6.26 |
+| Folly Format | folly::format | 1.87 |
+
+{fmt} is the fastest of the benchmarked methods, \~20% faster than
+`printf`.
+
+The above results were generated by building `tinyformat_test.cpp` on
+macOS 12.6.1 with `clang++ -O3 -DNDEBUG -DSPEED_TEST -DHAVE_FORMAT`, and
+taking the best of three runs. In the test, the format string
+`"%0.10f:%04d:%+g:%s:%p:%c:%%\n"` or equivalent is filled 2,000,000
+times with output sent to `/dev/null`; for further details refer to the
+[source](https://github.com/fmtlib/format-benchmark/blob/master/src/tinyformat-test.cc).
+
+{fmt} is up to 20-30x faster than `std::ostringstream` and `sprintf` on
+IEEE754 `float` and `double` formatting
+([dtoa-benchmark](https://github.com/fmtlib/dtoa-benchmark)) and faster
+than [double-conversion](https://github.com/google/double-conversion)
+and [ryu](https://github.com/ulfjack/ryu):
+
+[![image](https://user-images.githubusercontent.com/576385/95684665-11719600-0ba8-11eb-8e5b-972ff4e49428.png)](https://fmt.dev/unknown_mac64_clang12.0.html)
+
+## Compile time and code bloat
+
+The script
+[bloat-test.py](https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py)
+from [format-benchmark](https://github.com/fmtlib/format-benchmark)
+tests compile time and code bloat for nontrivial projects. It generates
+100 translation units and uses `printf()` or its alternative five times
+in each to simulate a medium-sized project. The resulting executable
+size and compile time (Apple LLVM version 8.1.0 (clang-802.0.42), macOS
+Sierra, best of three) is shown in the following tables.
+
+**Optimized build (-O3)**
+
+| Method | Compile Time, s | Executable size, KiB | Stripped size, KiB |
+|---------------|-----------------|----------------------|--------------------|
+| printf | 2.6 | 29 | 26 |
+| printf+string | 16.4 | 29 | 26 |
+| iostreams | 31.1 | 59 | 55 |
+| {fmt} | 19.0 | 37 | 34 |
+| Boost Format | 91.9 | 226 | 203 |
+| Folly Format | 115.7 | 101 | 88 |
+
+As you can see, {fmt} has 60% less overhead in terms of resulting binary
+code size compared to iostreams and comes pretty close to `printf`.
+Boost Format and Folly Format have the largest overheads.
+
+`printf+string` is the same as `printf` but with an extra ``
+include to measure the overhead of the latter.
+
+**Non-optimized build**
+
+| Method | Compile Time, s | Executable size, KiB | Stripped size, KiB |
+|---------------|-----------------|----------------------|--------------------|
+| printf | 2.2 | 33 | 30 |
+| printf+string | 16.0 | 33 | 30 |
+| iostreams | 28.3 | 56 | 52 |
+| {fmt} | 18.2 | 59 | 50 |
+| Boost Format | 54.1 | 365 | 303 |
+| Folly Format | 79.9 | 445 | 430 |
+
+`libc`, `lib(std)c++`, and `libfmt` are all linked as shared libraries
+to compare formatting function overhead only. Boost Format is a
+header-only library so it doesn\'t provide any linkage options.
+
+## Running the tests
+
+Please refer to [Building the
+library](https://fmt.dev/latest/usage.html#building-the-library) for
+instructions on how to build the library and run the unit tests.
+
+Benchmarks reside in a separate repository,
+[format-benchmarks](https://github.com/fmtlib/format-benchmark), so to
+run the benchmarks you first need to clone this repository and generate
+Makefiles with CMake:
+
+ $ git clone --recursive https://github.com/fmtlib/format-benchmark.git
+ $ cd format-benchmark
+ $ cmake .
+
+Then you can run the speed test:
+
+ $ make speed-test
+
+or the bloat test:
+
+ $ make bloat-test
+
+# Migrating code
+
+[clang-tidy](https://clang.llvm.org/extra/clang-tidy/) v17 (not yet
+released) provides the
+[modernize-use-std-print](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-print.html)
+check that is capable of converting occurrences of `printf` and
+`fprintf` to `fmt::print` if configured to do so. (By default it
+converts to `std::print`.)
+
+# Notable projects using this library
+
+- [0 A.D.](https://play0ad.com/): a free, open-source, cross-platform
+ real-time strategy game
+- [AMPL/MP](https://github.com/ampl/mp): an open-source library for
+ mathematical programming
+- [Apple's FoundationDB](https://github.com/apple/foundationdb): an open-source,
+ distributed, transactional key-value store
+- [Aseprite](https://github.com/aseprite/aseprite): animated sprite
+ editor & pixel art tool
+- [AvioBook](https://www.aviobook.aero/en): a comprehensive aircraft
+ operations suite
+- [Blizzard Battle.net](https://battle.net/): an online gaming
+ platform
+- [Celestia](https://celestia.space/): real-time 3D visualization of
+ space
+- [Ceph](https://ceph.com/): a scalable distributed storage system
+- [ccache](https://ccache.dev/): a compiler cache
+- [ClickHouse](https://github.com/ClickHouse/ClickHouse): an
+ analytical database management system
+- [Contour](https://github.com/contour-terminal/contour/): a modern
+ terminal emulator
+- [CUAUV](https://cuauv.org/): Cornell University\'s autonomous
+ underwater vehicle
+- [Drake](https://drake.mit.edu/): a planning, control, and analysis
+ toolbox for nonlinear dynamical systems (MIT)
+- [Envoy](https://lyft.github.io/envoy/): C++ L7 proxy and
+ communication bus (Lyft)
+- [FiveM](https://fivem.net/): a modification framework for GTA V
+- [fmtlog](https://github.com/MengRao/fmtlog): a performant
+ fmtlib-style logging library with latency in nanoseconds
+- [Folly](https://github.com/facebook/folly): Facebook open-source
+ library
+- [GemRB](https://gemrb.org/): a portable open-source implementation
+ of Bioware's Infinity Engine
+- [Grand Mountain
+ Adventure](https://store.steampowered.com/app/1247360/Grand_Mountain_Adventure/):
+ a beautiful open-world ski & snowboarding game
+- [HarpyWar/pvpgn](https://github.com/pvpgn/pvpgn-server): Player vs
+ Player Gaming Network with tweaks
+- [KBEngine](https://github.com/kbengine/kbengine): an open-source
+ MMOG server engine
+- [Keypirinha](https://keypirinha.com/): a semantic launcher for
+ Windows
+- [Kodi](https://kodi.tv/) (formerly xbmc): home theater software
+- [Knuth](https://kth.cash/): high-performance Bitcoin full-node
+- [libunicode](https://github.com/contour-terminal/libunicode/): a
+ modern C++17 Unicode library
+- [MariaDB](https://mariadb.org/): relational database management
+ system
+- [Microsoft Verona](https://github.com/microsoft/verona): research
+ programming language for concurrent ownership
+- [MongoDB](https://mongodb.com/): distributed document database
+- [MongoDB Smasher](https://github.com/duckie/mongo_smasher): a small
+ tool to generate randomized datasets
+- [OpenSpace](https://openspaceproject.com/): an open-source
+ astrovisualization framework
+- [PenUltima Online (POL)](https://www.polserver.com/): an MMO server,
+ compatible with most Ultima Online clients
+- [PyTorch](https://github.com/pytorch/pytorch): an open-source
+ machine learning library
+- [quasardb](https://www.quasardb.net/): a distributed,
+ high-performance, associative database
+- [Quill](https://github.com/odygrd/quill): asynchronous low-latency
+ logging library
+- [QKW](https://github.com/ravijanjam/qkw): generalizing aliasing to
+ simplify navigation, and executing complex multi-line terminal
+ command sequences
+- [redis-cerberus](https://github.com/HunanTV/redis-cerberus): a Redis
+ cluster proxy
+- [redpanda](https://vectorized.io/redpanda): a 10x faster Kafka®
+ replacement for mission-critical systems written in C++
+- [rpclib](http://rpclib.net/): a modern C++ msgpack-RPC server and
+ client library
+- [Salesforce Analytics
+ Cloud](https://www.salesforce.com/analytics-cloud/overview/):
+ business intelligence software
+- [Scylla](https://www.scylladb.com/): a Cassandra-compatible NoSQL
+ data store that can handle 1 million transactions per second on a
+ single server
+- [Seastar](http://www.seastar-project.org/): an advanced, open-source
+ C++ framework for high-performance server applications on modern
+ hardware
+- [spdlog](https://github.com/gabime/spdlog): super fast C++ logging
+ library
+- [Stellar](https://www.stellar.org/): financial platform
+- [Touch Surgery](https://www.touchsurgery.com/): surgery simulator
+- [TrinityCore](https://github.com/TrinityCore/TrinityCore):
+ open-source MMORPG framework
+- [🐙 userver framework](https://userver.tech/): open-source
+ asynchronous framework with a rich set of abstractions and database
+ drivers
+- [Windows Terminal](https://github.com/microsoft/terminal): the new
+ Windows terminal
+
+[More\...](https://github.com/search?q=fmtlib&type=Code)
+
+If you are aware of other projects using this library, please let me
+know by [email](mailto:victor.zverovich@gmail.com) or by submitting an
+[issue](https://github.com/fmtlib/fmt/issues).
+
+# Motivation
+
+So why yet another formatting library?
+
+There are plenty of methods for doing this task, from standard ones like
+the printf family of function and iostreams to Boost Format and
+FastFormat libraries. The reason for creating a new library is that
+every existing solution that I found either had serious issues or
+didn\'t provide all the features I needed.
+
+## printf
+
+The good thing about `printf` is that it is pretty fast and readily
+available being a part of the C standard library. The main drawback is
+that it doesn\'t support user-defined types. `printf` also has safety
+issues although they are somewhat mitigated with [\_\_attribute\_\_
+((format (printf,
+\...))](https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) in
+GCC. There is a POSIX extension that adds positional arguments required
+for
+[i18n](https://en.wikipedia.org/wiki/Internationalization_and_localization)
+to `printf` but it is not a part of C99 and may not be available on some
+platforms.
+
+## iostreams
+
+The main issue with iostreams is best illustrated with an example:
+
+``` c++
+std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n";
+```
+
+which is a lot of typing compared to printf:
+
+``` c++
+printf("%.2f\n", 1.23456);
+```
+
+Matthew Wilson, the author of FastFormat, called this \"chevron hell\".
+iostreams don\'t support positional arguments by design.
+
+The good part is that iostreams support user-defined types and are safe
+although error handling is awkward.
+
+## Boost Format
+
+This is a very powerful library that supports both `printf`-like format
+strings and positional arguments. Its main drawback is performance.
+According to various benchmarks, it is much slower than other methods
+considered here. Boost Format also has excessive build times and severe
+code bloat issues (see [Benchmarks](#benchmarks)).
+
+## FastFormat
+
+This is an interesting library that is fast, safe, and has positional
+arguments. However, it has significant limitations, citing its author:
+
+> Three features that have no hope of being accommodated within the
+> current design are:
+>
+> - Leading zeros (or any other non-space padding)
+> - Octal/hexadecimal encoding
+> - Runtime width/alignment specification
+
+It is also quite big and has a heavy dependency, STLSoft, which might be
+too restrictive for using it in some projects.
+
+## Boost Spirit.Karma
+
+This is not a formatting library but I decided to include it here for
+completeness. As iostreams, it suffers from the problem of mixing
+verbatim text with arguments. The library is pretty fast, but slower on
+integer formatting than `fmt::format_to` with format string compilation
+on Karma\'s own benchmark, see [Converting a hundred million integers to
+strings per
+second](http://www.zverovich.net/2020/06/13/fast-int-to-string-revisited.html).
+
+# License
+
+{fmt} is distributed under the MIT
+[license](https://github.com/fmtlib/fmt/blob/master/LICENSE).
+
+# Documentation License
+
+The [Format String Syntax](https://fmt.dev/latest/syntax.html) section
+in the documentation is based on the one from Python [string module
+documentation](https://docs.python.org/3/library/string.html#module-string).
+For this reason, the documentation is distributed under the Python
+Software Foundation license available in
+[doc/python-license.txt](https://raw.github.com/fmtlib/fmt/master/doc/python-license.txt).
+It only applies if you distribute the documentation of {fmt}.
+
+# Maintainers
+
+The {fmt} library is maintained by Victor Zverovich
+([vitaut](https://github.com/vitaut)) with contributions from many other
+people. See
+[Contributors](https://github.com/fmtlib/fmt/graphs/contributors) and
+[Releases](https://github.com/fmtlib/fmt/releases) for some of the
+names. Let us know if your contribution is not listed or mentioned
+incorrectly and we\'ll make it right.
+
+# Security Policy
+
+To report a security issue, please disclose it at [security
+advisory](https://github.com/fmtlib/fmt/security/advisories/new).
+
+This project is maintained by a team of volunteers on a
+reasonable-effort basis. As such, please give us at least 90 days to
+work on a fix before public exposure.
diff --git a/contrib/fmt/README.rst b/contrib/fmt/README.rst
deleted file mode 100644
index f51fefab7..000000000
--- a/contrib/fmt/README.rst
+++ /dev/null
@@ -1,542 +0,0 @@
-.. image:: https://user-images.githubusercontent.com/
- 576385/156254208-f5b743a9-88cf-439d-b0c0-923d53e8d551.png
- :width: 25%
- :alt: {fmt}
-
-.. image:: https://github.com/fmtlib/fmt/workflows/linux/badge.svg
- :target: https://github.com/fmtlib/fmt/actions?query=workflow%3Alinux
-
-.. image:: https://github.com/fmtlib/fmt/workflows/macos/badge.svg
- :target: https://github.com/fmtlib/fmt/actions?query=workflow%3Amacos
-
-.. image:: https://github.com/fmtlib/fmt/workflows/windows/badge.svg
- :target: https://github.com/fmtlib/fmt/actions?query=workflow%3Awindows
-
-.. image:: https://oss-fuzz-build-logs.storage.googleapis.com/badges/fmt.svg
- :alt: fmt is continuously fuzzed at oss-fuzz
- :target: https://bugs.chromium.org/p/oss-fuzz/issues/list?\
- colspec=ID%20Type%20Component%20Status%20Proj%20Reported%20Owner%20\
- Summary&q=proj%3Dfmt&can=1
-
-.. image:: https://img.shields.io/badge/stackoverflow-fmt-blue.svg
- :alt: Ask questions at StackOverflow with the tag fmt
- :target: https://stackoverflow.com/questions/tagged/fmt
-
-**{fmt}** is an open-source formatting library providing a fast and safe
-alternative to C stdio and C++ iostreams.
-
-If you like this project, please consider donating to one of the funds that
-help victims of the war in Ukraine: https://www.stopputin.net/.
-
-`Documentation `__
-
-`Cheat Sheets `__
-
-Q&A: ask questions on `StackOverflow with the tag fmt
-`_.
-
-Try {fmt} in `Compiler Explorer `_.
-
-Features
---------
-
-* Simple `format API `_ with positional arguments
- for localization
-* Implementation of `C++20 std::format
- `__
-* `Format string syntax `_ similar to Python's
- `format `_
-* Fast IEEE 754 floating-point formatter with correct rounding, shortness and
- round-trip guarantees using the `Dragonbox `_
- algorithm
-* Portable Unicode support
-* Safe `printf implementation
- `_ including the POSIX
- extension for positional arguments
-* Extensibility: `support for user-defined types
- `_
-* High performance: faster than common standard library implementations of
- ``(s)printf``, iostreams, ``to_string`` and ``to_chars``, see `Speed tests`_
- and `Converting a hundred million integers to strings per second
- `_
-* Small code size both in terms of source code with the minimum configuration
- consisting of just three files, ``core.h``, ``format.h`` and ``format-inl.h``,
- and compiled code; see `Compile time and code bloat`_
-* Reliability: the library has an extensive set of `tests
- `_ and is `continuously fuzzed
- `_
-* Safety: the library is fully type-safe, errors in format strings can be
- reported at compile time, automatic memory management prevents buffer overflow
- errors
-* Ease of use: small self-contained code base, no external dependencies,
- permissive MIT `license
- `_
-* `Portability `_ with
- consistent output across platforms and support for older compilers
-* Clean warning-free codebase even on high warning levels such as
- ``-Wall -Wextra -pedantic``
-* Locale independence by default
-* Optional header-only configuration enabled with the ``FMT_HEADER_ONLY`` macro
-
-See the `documentation `_ for more details.
-
-Examples
---------
-
-**Print to stdout** (`run `_)
-
-.. code:: c++
-
- #include
-
- int main() {
- fmt::print("Hello, world!\n");
- }
-
-**Format a string** (`run `_)
-
-.. code:: c++
-
- std::string s = fmt::format("The answer is {}.", 42);
- // s == "The answer is 42."
-
-**Format a string using positional arguments** (`run `_)
-
-.. code:: c++
-
- std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
- // s == "I'd rather be happy than right."
-
-**Print chrono durations** (`run `_)
-
-.. code:: c++
-
- #include
-
- int main() {
- using namespace std::literals::chrono_literals;
- fmt::print("Default format: {} {}\n", 42s, 100ms);
- fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);
- }
-
-Output::
-
- Default format: 42s 100ms
- strftime-like format: 03:15:30
-
-**Print a container** (`run `_)
-
-.. code:: c++
-
- #include
- #include
-
- int main() {
- std::vector v = {1, 2, 3};
- fmt::print("{}\n", v);
- }
-
-Output::
-
- [1, 2, 3]
-
-**Check a format string at compile time**
-
-.. code:: c++
-
- std::string s = fmt::format("{:d}", "I am not a number");
-
-This gives a compile-time error in C++20 because ``d`` is an invalid format
-specifier for a string.
-
-**Write a file from a single thread**
-
-.. code:: c++
-
- #include
-
- int main() {
- auto out = fmt::output_file("guide.txt");
- out.print("Don't {}", "Panic");
- }
-
-This can be `5 to 9 times faster than fprintf
-`_.
-
-**Print with colors and text styles**
-
-.. code:: c++
-
- #include
-
- int main() {
- fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,
- "Hello, {}!\n", "world");
- fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
- fmt::emphasis::underline, "Hello, {}!\n", "мир");
- fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
- "Hello, {}!\n", "世界");
- }
-
-Output on a modern terminal:
-
-.. image:: https://user-images.githubusercontent.com/
- 576385/88485597-d312f600-cf2b-11ea-9cbe-61f535a86e28.png
-
-Benchmarks
-----------
-
-Speed tests
-~~~~~~~~~~~
-
-================= ============= ===========
-Library Method Run Time, s
-================= ============= ===========
-libc printf 0.91
-libc++ std::ostream 2.49
-{fmt} 9.1 fmt::print 0.74
-Boost Format 1.80 boost::format 6.26
-Folly Format folly::format 1.87
-================= ============= ===========
-
-{fmt} is the fastest of the benchmarked methods, ~20% faster than ``printf``.
-
-The above results were generated by building ``tinyformat_test.cpp`` on macOS
-12.6.1 with ``clang++ -O3 -DNDEBUG -DSPEED_TEST -DHAVE_FORMAT``, and taking the
-best of three runs. In the test, the format string ``"%0.10f:%04d:%+g:%s:%p:%c:%%\n"``
-or equivalent is filled 2,000,000 times with output sent to ``/dev/null``; for
-further details refer to the `source
-`_.
-
-{fmt} is up to 20-30x faster than ``std::ostringstream`` and ``sprintf`` on
-IEEE754 ``float`` and ``double`` formatting (`dtoa-benchmark `_)
-and faster than `double-conversion `_ and
-`ryu `_:
-
-.. image:: https://user-images.githubusercontent.com/576385/
- 95684665-11719600-0ba8-11eb-8e5b-972ff4e49428.png
- :target: https://fmt.dev/unknown_mac64_clang12.0.html
-
-Compile time and code bloat
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-The script `bloat-test.py
-`_
-from `format-benchmark `_
-tests compile time and code bloat for nontrivial projects.
-It generates 100 translation units and uses ``printf()`` or its alternative
-five times in each to simulate a medium-sized project. The resulting
-executable size and compile time (Apple LLVM version 8.1.0 (clang-802.0.42),
-macOS Sierra, best of three) is shown in the following tables.
-
-**Optimized build (-O3)**
-
-============= =============== ==================== ==================
-Method Compile Time, s Executable size, KiB Stripped size, KiB
-============= =============== ==================== ==================
-printf 2.6 29 26
-printf+string 16.4 29 26
-iostreams 31.1 59 55
-{fmt} 19.0 37 34
-Boost Format 91.9 226 203
-Folly Format 115.7 101 88
-============= =============== ==================== ==================
-
-As you can see, {fmt} has 60% less overhead in terms of resulting binary code
-size compared to iostreams and comes pretty close to ``printf``. Boost Format
-and Folly Format have the largest overheads.
-
-``printf+string`` is the same as ``printf`` but with an extra ````
-include to measure the overhead of the latter.
-
-**Non-optimized build**
-
-============= =============== ==================== ==================
-Method Compile Time, s Executable size, KiB Stripped size, KiB
-============= =============== ==================== ==================
-printf 2.2 33 30
-printf+string 16.0 33 30
-iostreams 28.3 56 52
-{fmt} 18.2 59 50
-Boost Format 54.1 365 303
-Folly Format 79.9 445 430
-============= =============== ==================== ==================
-
-``libc``, ``lib(std)c++``, and ``libfmt`` are all linked as shared libraries to
-compare formatting function overhead only. Boost Format is a
-header-only library so it doesn't provide any linkage options.
-
-Running the tests
-~~~~~~~~~~~~~~~~~
-
-Please refer to `Building the library`__ for instructions on how to build
-the library and run the unit tests.
-
-__ https://fmt.dev/latest/usage.html#building-the-library
-
-Benchmarks reside in a separate repository,
-`format-benchmarks `_,
-so to run the benchmarks you first need to clone this repository and
-generate Makefiles with CMake::
-
- $ git clone --recursive https://github.com/fmtlib/format-benchmark.git
- $ cd format-benchmark
- $ cmake .
-
-Then you can run the speed test::
-
- $ make speed-test
-
-or the bloat test::
-
- $ make bloat-test
-
-Migrating code
---------------
-
-`clang-tidy `_ v17 (not yet
-released) provides the `modernize-use-std-print
-`_
-check that is capable of converting occurrences of ``printf`` and
-``fprintf`` to ``fmt::print`` if configured to do so. (By default it
-converts to ``std::print``.)
-
-Projects using this library
----------------------------
-
-* `0 A.D. `_: a free, open-source, cross-platform
- real-time strategy game
-
-* `AMPL/MP `_:
- an open-source library for mathematical programming
-
-* `Aseprite `_:
- animated sprite editor & pixel art tool
-
-* `AvioBook `_: a comprehensive aircraft
- operations suite
-
-* `Blizzard Battle.net `_: an online gaming platform
-
-* `Celestia `_: real-time 3D visualization of space
-
-* `Ceph `_: a scalable distributed storage system
-
-* `ccache `_: a compiler cache
-
-* `ClickHouse `_: an analytical database
- management system
-
-* `Contour `_: a modern terminal emulator
-
-* `CUAUV `_: Cornell University's autonomous underwater
- vehicle
-
-* `Drake `_: a planning, control, and analysis toolbox
- for nonlinear dynamical systems (MIT)
-
-* `Envoy `_: C++ L7 proxy and communication bus
- (Lyft)
-
-* `FiveM `_: a modification framework for GTA V
-
-* `fmtlog `_: a performant fmtlib-style
- logging library with latency in nanoseconds
-
-* `Folly `_: Facebook open-source library
-
-* `GemRB `_: a portable open-source implementation of
- Bioware’s Infinity Engine
-
-* `Grand Mountain Adventure
- `_:
- a beautiful open-world ski & snowboarding game
-
-* `HarpyWar/pvpgn `_:
- Player vs Player Gaming Network with tweaks
-
-* `KBEngine `_: an open-source MMOG server
- engine
-
-* `Keypirinha `_: a semantic launcher for Windows
-
-* `Kodi `_ (formerly xbmc): home theater software
-
-* `Knuth `_: high-performance Bitcoin full-node
-
-* `libunicode `_: a modern C++17 Unicode library
-
-* `MariaDB `_: relational database management system
-
-* `Microsoft Verona `_:
- research programming language for concurrent ownership
-
-* `MongoDB `_: distributed document database
-
-* `MongoDB Smasher `_: a small tool to
- generate randomized datasets
-
-* `OpenSpace `_: an open-source
- astrovisualization framework
-
-* `PenUltima Online (POL) `_:
- an MMO server, compatible with most Ultima Online clients
-
-* `PyTorch `_: an open-source machine
- learning library
-
-* `quasardb `_: a distributed, high-performance,
- associative database
-
-* `Quill `_: asynchronous low-latency logging library
-
-* `QKW `_: generalizing aliasing to simplify
- navigation, and executing complex multi-line terminal command sequences
-
-* `redis-cerberus `_: a Redis cluster
- proxy
-
-* `redpanda `_: a 10x faster Kafka® replacement
- for mission-critical systems written in C++
-
-* `rpclib `_: a modern C++ msgpack-RPC server and client
- library
-
-* `Salesforce Analytics Cloud
- `_:
- business intelligence software
-
-* `Scylla `_: a Cassandra-compatible NoSQL data store
- that can handle 1 million transactions per second on a single server
-
-* `Seastar `_: an advanced, open-source C++
- framework for high-performance server applications on modern hardware
-
-* `spdlog `_: super fast C++ logging library
-
-* `Stellar `_: financial platform
-
-* `Touch Surgery `_: surgery simulator
-
-* `TrinityCore `_: open-source
- MMORPG framework
-
-* `🐙 userver framework `_: open-source asynchronous
- framework with a rich set of abstractions and database drivers
-
-* `Windows Terminal `_: the new Windows
- terminal
-
-`More... `_
-
-If you are aware of other projects using this library, please let me know
-by `email `_ or by submitting an
-`issue `_.
-
-Motivation
-----------
-
-So why yet another formatting library?
-
-There are plenty of methods for doing this task, from standard ones like
-the printf family of function and iostreams to Boost Format and FastFormat
-libraries. The reason for creating a new library is that every existing
-solution that I found either had serious issues or didn't provide
-all the features I needed.
-
-printf
-~~~~~~
-
-The good thing about ``printf`` is that it is pretty fast and readily available
-being a part of the C standard library. The main drawback is that it
-doesn't support user-defined types. ``printf`` also has safety issues although
-they are somewhat mitigated with `__attribute__ ((format (printf, ...))
-`_ in GCC.
-There is a POSIX extension that adds positional arguments required for
-`i18n `_
-to ``printf`` but it is not a part of C99 and may not be available on some
-platforms.
-
-iostreams
-~~~~~~~~~
-
-The main issue with iostreams is best illustrated with an example:
-
-.. code:: c++
-
- std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n";
-
-which is a lot of typing compared to printf:
-
-.. code:: c++
-
- printf("%.2f\n", 1.23456);
-
-Matthew Wilson, the author of FastFormat, called this "chevron hell". iostreams
-don't support positional arguments by design.
-
-The good part is that iostreams support user-defined types and are safe although
-error handling is awkward.
-
-Boost Format
-~~~~~~~~~~~~
-
-This is a very powerful library that supports both ``printf``-like format
-strings and positional arguments. Its main drawback is performance. According to
-various benchmarks, it is much slower than other methods considered here. Boost
-Format also has excessive build times and severe code bloat issues (see
-`Benchmarks`_).
-
-FastFormat
-~~~~~~~~~~
-
-This is an interesting library that is fast, safe, and has positional arguments.
-However, it has significant limitations, citing its author:
-
- Three features that have no hope of being accommodated within the
- current design are:
-
- * Leading zeros (or any other non-space padding)
- * Octal/hexadecimal encoding
- * Runtime width/alignment specification
-
-It is also quite big and has a heavy dependency, STLSoft, which might be too
-restrictive for using it in some projects.
-
-Boost Spirit.Karma
-~~~~~~~~~~~~~~~~~~
-
-This is not a formatting library but I decided to include it here for
-completeness. As iostreams, it suffers from the problem of mixing verbatim text
-with arguments. The library is pretty fast, but slower on integer formatting
-than ``fmt::format_to`` with format string compilation on Karma's own benchmark,
-see `Converting a hundred million integers to strings per second
-`_.
-
-License
--------
-
-{fmt} is distributed under the MIT `license
-`_.
-
-Documentation License
----------------------
-
-The `Format String Syntax `_
-section in the documentation is based on the one from Python `string module
-documentation `_.
-For this reason, the documentation is distributed under the Python Software
-Foundation license available in `doc/python-license.txt
-`_.
-It only applies if you distribute the documentation of {fmt}.
-
-Maintainers
------------
-
-The {fmt} library is maintained by Victor Zverovich (`vitaut
-`_) with contributions from many other people.
-See `Contributors `_ and
-`Releases `_ for some of the names.
-Let us know if your contribution is not listed or mentioned incorrectly and
-we'll make it right.
diff --git a/contrib/fmt/include/fmt/args.h b/contrib/fmt/include/fmt/args.h
index 2d684e7cc..ad1654bbb 100644
--- a/contrib/fmt/include/fmt/args.h
+++ b/contrib/fmt/include/fmt/args.h
@@ -22,8 +22,9 @@ template struct is_reference_wrapper : std::false_type {};
template
struct is_reference_wrapper> : std::true_type {};
-template const T& unwrap(const T& v) { return v; }
-template const T& unwrap(const std::reference_wrapper& v) {
+template auto unwrap(const T& v) -> const T& { return v; }
+template
+auto unwrap(const std::reference_wrapper& v) -> const T& {
return static_cast(v);
}
@@ -50,7 +51,7 @@ class dynamic_arg_list {
std::unique_ptr> head_;
public:
- template const T& push(const Arg& arg) {
+ template auto push(const Arg& arg) -> const T& {
auto new_node = std::unique_ptr>(new typed_node(arg));
auto& value = new_node->value;
new_node->next = std::move(head_);
@@ -110,14 +111,14 @@ class dynamic_format_arg_store
friend class basic_format_args;
- unsigned long long get_types() const {
+ auto get_types() const -> unsigned long long {
return detail::is_unpacked_bit | data_.size() |
(named_info_.empty()
? 0ULL
: static_cast(detail::has_named_args_bit));
}
- const basic_format_arg* data() const {
+ auto data() const -> const basic_format_arg* {
return named_info_.empty() ? data_.data() : data_.data() + 1;
}
diff --git a/contrib/fmt/include/fmt/chrono.h b/contrib/fmt/include/fmt/chrono.h
index ff3e1445b..9d54574e1 100644
--- a/contrib/fmt/include/fmt/chrono.h
+++ b/contrib/fmt/include/fmt/chrono.h
@@ -18,7 +18,7 @@
#include
#include
-#include "format.h"
+#include "ostream.h" // formatbuf
FMT_BEGIN_NAMESPACE
@@ -72,7 +72,8 @@ template ::value &&
std::numeric_limits::is_signed ==
std::numeric_limits::is_signed)>
-FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
+FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
+ -> To {
ec = 0;
using F = std::numeric_limits;
using T = std::numeric_limits;
@@ -101,7 +102,8 @@ template ::value &&
std::numeric_limits::is_signed !=
std::numeric_limits::is_signed)>
-FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
+FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
+ -> To {
ec = 0;
using F = std::numeric_limits;
using T = std::numeric_limits;
@@ -133,7 +135,8 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
template ::value)>
-FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
+FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec)
+ -> To {
ec = 0;
return from;
} // function
@@ -154,7 +157,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
// clang-format on
template ::value)>
-FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {
+FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To {
ec = 0;
using T = std::numeric_limits;
static_assert(std::is_floating_point::value, "From must be floating");
@@ -176,7 +179,7 @@ FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {
template ::value)>
-FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {
+FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To {
ec = 0;
static_assert(std::is_floating_point::value, "From must be floating");
return from;
@@ -188,8 +191,8 @@ FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) {
template ::value),
FMT_ENABLE_IF(std::is_integral::value)>
-To safe_duration_cast(std::chrono::duration from,
- int& ec) {
+auto safe_duration_cast(std::chrono::duration from,
+ int& ec) -> To {
using From = std::chrono::duration;
ec = 0;
// the basic idea is that we need to convert from count() in the from type
@@ -240,8 +243,8 @@ To safe_duration_cast(std::chrono::duration from,
template ::value),
FMT_ENABLE_IF(std::is_floating_point::value)>
-To safe_duration_cast(std::chrono::duration from,
- int& ec) {
+auto safe_duration_cast(std::chrono::duration from,
+ int& ec) -> To {
using From = std::chrono::duration;
ec = 0;
if (std::isnan(from.count())) {
@@ -321,12 +324,12 @@ To safe_duration_cast(std::chrono::duration from,
namespace detail {
template struct null {};
-inline null<> localtime_r FMT_NOMACRO(...) { return null<>(); }
-inline null<> localtime_s(...) { return null<>(); }
-inline null<> gmtime_r(...) { return null<>(); }
-inline null<> gmtime_s(...) { return null<>(); }
+inline auto localtime_r FMT_NOMACRO(...) -> null<> { return null<>(); }
+inline auto localtime_s(...) -> null<> { return null<>(); }
+inline auto gmtime_r(...) -> null<> { return null<>(); }
+inline auto gmtime_s(...) -> null<> { return null<>(); }
-inline const std::locale& get_classic_locale() {
+inline auto get_classic_locale() -> const std::locale& {
static const auto& locale = std::locale::classic();
return locale;
}
@@ -336,8 +339,6 @@ template struct codecvt_result {
CodeUnit buf[max_size];
CodeUnit* end;
};
-template
-constexpr const size_t codecvt_result::max_size;
template
void write_codecvt(codecvt_result& out, string_view in_buf,
@@ -408,8 +409,7 @@ inline void do_write(buffer& buf, const std::tm& time,
auto&& format_buf = formatbuf>(buf);
auto&& os = std::basic_ostream(&format_buf);
os.imbue(loc);
- using iterator = std::ostreambuf_iterator;
- const auto& facet = std::use_facet>(loc);
+ const auto& facet = std::use_facet>(loc);
auto end = facet.put(os, os, Char(' '), &time, format, modifier);
if (end.failed()) FMT_THROW(format_error("failed to format time"));
}
@@ -432,6 +432,51 @@ auto write(OutputIt out, const std::tm& time, const std::locale& loc,
return write_encoded_tm_str(out, string_view(buf.data(), buf.size()), loc);
}
+template
+struct is_same_arithmetic_type
+ : public std::integral_constant::value &&
+ std::is_integral::value) ||
+ (std::is_floating_point::value &&
+ std::is_floating_point::value)> {
+};
+
+template <
+ typename To, typename FromRep, typename FromPeriod,
+ FMT_ENABLE_IF(is_same_arithmetic_type::value)>
+auto fmt_duration_cast(std::chrono::duration from) -> To {
+#if FMT_SAFE_DURATION_CAST
+ // Throwing version of safe_duration_cast is only available for
+ // integer to integer or float to float casts.
+ int ec;
+ To to = safe_duration_cast::safe_duration_cast(from, ec);
+ if (ec) FMT_THROW(format_error("cannot format duration"));
+ return to;
+#else
+ // Standard duration cast, may overflow.
+ return std::chrono::duration_cast(from);
+#endif
+}
+
+template <
+ typename To, typename FromRep, typename FromPeriod,
+ FMT_ENABLE_IF(!is_same_arithmetic_type::value)>
+auto fmt_duration_cast(std::chrono::duration from) -> To {
+ // Mixed integer <-> float cast is not supported by safe_duration_cast.
+ return std::chrono::duration_cast(from);
+}
+
+template
+auto to_time_t(
+ std::chrono::time_point time_point)
+ -> std::time_t {
+ // Cannot use std::chrono::system_clock::to_time_t since this would first
+ // require a cast to std::chrono::system_clock::time_point, which could
+ // overflow.
+ return fmt_duration_cast>(
+ time_point.time_since_epoch())
+ .count();
+}
} // namespace detail
FMT_BEGIN_EXPORT
@@ -441,29 +486,29 @@ FMT_BEGIN_EXPORT
expressed in local time. Unlike ``std::localtime``, this function is
thread-safe on most platforms.
*/
-inline std::tm localtime(std::time_t time) {
+inline auto localtime(std::time_t time) -> std::tm {
struct dispatcher {
std::time_t time_;
std::tm tm_;
dispatcher(std::time_t t) : time_(t) {}
- bool run() {
+ auto run() -> bool {
using namespace fmt::detail;
return handle(localtime_r(&time_, &tm_));
}
- bool handle(std::tm* tm) { return tm != nullptr; }
+ auto handle(std::tm* tm) -> bool { return tm != nullptr; }
- bool handle(detail::null<>) {
+ auto handle(detail::null<>) -> bool {
using namespace fmt::detail;
return fallback(localtime_s(&tm_, &time_));
}
- bool fallback(int res) { return res == 0; }
+ auto fallback(int res) -> bool { return res == 0; }
#if !FMT_MSC_VERSION
- bool fallback(detail::null<>) {
+ auto fallback(detail::null<>) -> bool {
using namespace fmt::detail;
std::tm* tm = std::localtime(&time_);
if (tm) tm_ = *tm;
@@ -480,8 +525,8 @@ inline std::tm localtime(std::time_t time) {
#if FMT_USE_LOCAL_TIME
template
inline auto localtime(std::chrono::local_time time) -> std::tm {
- return localtime(std::chrono::system_clock::to_time_t(
- std::chrono::current_zone()->to_sys(time)));
+ return localtime(
+ detail::to_time_t(std::chrono::current_zone()->to_sys(time)));
}
#endif
@@ -490,29 +535,29 @@ inline auto localtime(std::chrono::local_time time) -> std::tm {
expressed in Coordinated Universal Time (UTC). Unlike ``std::gmtime``, this
function is thread-safe on most platforms.
*/
-inline std::tm gmtime(std::time_t time) {
+inline auto gmtime(std::time_t time) -> std::tm {
struct dispatcher {
std::time_t time_;
std::tm tm_;
dispatcher(std::time_t t) : time_(t) {}
- bool run() {
+ auto run() -> bool {
using namespace fmt::detail;
return handle(gmtime_r(&time_, &tm_));
}
- bool handle(std::tm* tm) { return tm != nullptr; }
+ auto handle(std::tm* tm) -> bool { return tm != nullptr; }
- bool handle(detail::null<>) {
+ auto handle(detail::null<>) -> bool {
using namespace fmt::detail;
return fallback(gmtime_s(&tm_, &time_));
}
- bool fallback(int res) { return res == 0; }
+ auto fallback(int res) -> bool { return res == 0; }
#if !FMT_MSC_VERSION
- bool fallback(detail::null<>) {
+ auto fallback(detail::null<>) -> bool {
std::tm* tm = std::gmtime(&time_);
if (tm) tm_ = *tm;
return tm != nullptr;
@@ -525,9 +570,11 @@ inline std::tm gmtime(std::time_t time) {
return gt.tm_;
}
-inline std::tm gmtime(
- std::chrono::time_point time_point) {
- return gmtime(std::chrono::system_clock::to_time_t(time_point));
+template
+inline auto gmtime(
+ std::chrono::time_point time_point)
+ -> std::tm {
+ return gmtime(detail::to_time_t(time_point));
}
namespace detail {
@@ -566,7 +613,8 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
}
}
-template FMT_CONSTEXPR inline const char* get_units() {
+template
+FMT_CONSTEXPR inline auto get_units() -> const char* {
if (std::is_same::value) return "as";
if (std::is_same::value) return "fs";
if (std::is_same::value) return "ps";
@@ -584,8 +632,9 @@ template FMT_CONSTEXPR inline const char* get_units() {
if (std::is_same::value) return "Ts";
if (std::is_same::value) return "Ps";
if (std::is_same::value) return "Es";
- if (std::is_same>::value) return "m";
+ if (std::is_same>::value) return "min";
if (std::is_same>::value) return "h";
+ if (std::is_same>::value) return "d";
return nullptr;
}
@@ -621,9 +670,8 @@ auto write_padding(OutputIt out, pad_type pad) -> OutputIt {
// Parses a put_time-like format string and invokes handler actions.
template
-FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
- const Char* end,
- Handler&& handler) {
+FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
+ Handler&& handler) -> const Char* {
if (begin == end || *begin == '}') return begin;
if (*begin != '%') FMT_THROW(format_error("invalid format"));
auto ptr = begin;
@@ -954,25 +1002,25 @@ struct tm_format_checker : null_chrono_spec_handler {
FMT_CONSTEXPR void on_tz_name() {}
};
-inline const char* tm_wday_full_name(int wday) {
+inline auto tm_wday_full_name(int wday) -> const char* {
static constexpr const char* full_name_list[] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
return wday >= 0 && wday <= 6 ? full_name_list[wday] : "?";
}
-inline const char* tm_wday_short_name(int wday) {
+inline auto tm_wday_short_name(int wday) -> const char* {
static constexpr const char* short_name_list[] = {"Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat"};
return wday >= 0 && wday <= 6 ? short_name_list[wday] : "???";
}
-inline const char* tm_mon_full_name(int mon) {
+inline auto tm_mon_full_name(int mon) -> const char* {
static constexpr const char* full_name_list[] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
return mon >= 0 && mon <= 11 ? full_name_list[mon] : "?";
}
-inline const char* tm_mon_short_name(int mon) {
+inline auto tm_mon_short_name(int mon) -> const char* {
static constexpr const char* short_name_list[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
@@ -1004,21 +1052,21 @@ inline void tzset_once() {
// Converts value to Int and checks that it's in the range [0, upper).
template ::value)>
-inline Int to_nonnegative_int(T value, Int upper) {
- FMT_ASSERT(std::is_unsigned::value ||
- (value >= 0 && to_unsigned(value) <= to_unsigned(upper)),
- "invalid value");
- (void)upper;
+inline auto to_nonnegative_int(T value, Int upper) -> Int {
+ if (!std::is_unsigned::value &&
+ (value < 0 || to_unsigned(value) > to_unsigned(upper))) {
+ FMT_THROW(fmt::format_error("chrono value is out of range"));
+ }
return static_cast(value);
}
template ::value)>
-inline Int to_nonnegative_int(T value, Int upper) {
+inline auto to_nonnegative_int(T value, Int upper) -> Int {
if (value < 0 || value > static_cast(upper))
FMT_THROW(format_error("invalid value"));
return static_cast(value);
}
-constexpr long long pow10(std::uint32_t n) {
+constexpr auto pow10(std::uint32_t n) -> long long {
return n == 0 ? 1 : 10 * pow10(n - 1);
}
@@ -1052,13 +1100,12 @@ void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) {
std::chrono::seconds::rep>::type,
std::ratio<1, detail::pow10(num_fractional_digits)>>;
- const auto fractional =
- d - std::chrono::duration_cast(d);
+ const auto fractional = d - fmt_duration_cast(d);
const auto subseconds =
std::chrono::treat_as_floating_point<
typename subsecond_precision::rep>::value
? fractional.count()
- : std::chrono::duration_cast(fractional).count();
+ : fmt_duration_cast(fractional).count();
auto n = static_cast>(subseconds);
const int num_digits = detail::count_digits(n);
@@ -1109,11 +1156,11 @@ void write_floating_seconds(memory_buffer& buf, Duration duration,
num_fractional_digits = 6;
}
- format_to(std::back_inserter(buf), FMT_STRING("{:.{}f}"),
- std::fmod(val * static_cast(Duration::period::num) /
- static_cast(Duration::period::den),
- static_cast(60)),
- num_fractional_digits);
+ fmt::format_to(std::back_inserter(buf), FMT_STRING("{:.{}f}"),
+ std::fmod(val * static_cast(Duration::period::num) /
+ static_cast(Duration::period::den),
+ static_cast(60)),
+ num_fractional_digits);
}
template (l);
}
- // Algorithm:
- // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_from_a_month_and_day_of_the_month_or_ordinal_date
+ // Algorithm: https://en.wikipedia.org/wiki/ISO_week_date.
auto iso_year_weeks(long long curr_year) const noexcept -> int {
const auto prev_year = curr_year - 1;
const auto curr_p =
@@ -1315,7 +1361,7 @@ class tm_writer {
subsecs_(subsecs),
tm_(tm) {}
- OutputIt out() const { return out_; }
+ auto out() const -> OutputIt { return out_; }
FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) {
out_ = copy_str(begin, end, out_);
@@ -1579,6 +1625,7 @@ struct chrono_format_checker : null_chrono_spec_handler {
template
FMT_CONSTEXPR void on_text(const Char*, const Char*) {}
+ FMT_CONSTEXPR void on_day_of_year() {}
FMT_CONSTEXPR void on_24_hour(numeric_system, pad_type) {}
FMT_CONSTEXPR void on_12_hour(numeric_system, pad_type) {}
FMT_CONSTEXPR void on_minute(numeric_system, pad_type) {}
@@ -1597,16 +1644,16 @@ struct chrono_format_checker : null_chrono_spec_handler {
template ::value&& has_isfinite::value)>
-inline bool isfinite(T) {
+inline auto isfinite(T) -> bool {
return true;
}
template ::value)>
-inline T mod(T x, int y) {
+inline auto mod(T x, int y) -> T {
return x % static_cast(y);
}
template ::value)>
-inline T mod(T x, int y) {
+inline auto mod(T x, int y) -> T {
return std::fmod(x, static_cast(y));
}
@@ -1621,49 +1668,38 @@ template struct make_unsigned_or_unchanged {
using type = typename std::make_unsigned::type;
};
-#if FMT_SAFE_DURATION_CAST
-// throwing version of safe_duration_cast
-template
-To fmt_safe_duration_cast(std::chrono::duration from) {
- int ec;
- To to = safe_duration_cast::safe_duration_cast(from, ec);
- if (ec) FMT_THROW(format_error("cannot format duration"));
- return to;
-}
-#endif
-
template ::value)>
-inline std::chrono::duration get_milliseconds(
- std::chrono::duration d) {
+inline auto get_milliseconds(std::chrono::duration d)
+ -> std::chrono::duration {
// this may overflow and/or the result may not fit in the
// target type.
#if FMT_SAFE_DURATION_CAST
using CommonSecondsType =
typename std::common_type::type;
- const auto d_as_common = fmt_safe_duration_cast(d);
+ const auto d_as_common = fmt_duration_cast(d);
const auto d_as_whole_seconds =
- fmt_safe_duration_cast(d_as_common);
+ fmt_duration_cast(d_as_common);
// this conversion should be nonproblematic
const auto diff = d_as_common - d_as_whole_seconds;
const auto ms =
- fmt_safe_duration_cast>(diff);
+ fmt_duration_cast>(diff);
return ms;
#else
- auto s = std::chrono::duration_cast(d);
- return std::chrono::duration_cast(d - s);
+ auto s = fmt_duration_cast(d);
+ return fmt_duration_cast(d - s);
#endif
}
template ::value)>
-OutputIt format_duration_value(OutputIt out, Rep val, int) {
+auto format_duration_value(OutputIt out, Rep val, int) -> OutputIt {
return write(out, val);
}
template ::value)>
-OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
+auto format_duration_value(OutputIt out, Rep val, int precision) -> OutputIt {
auto specs = format_specs();
specs.precision = precision;
specs.type = precision >= 0 ? presentation_type::fixed_lower
@@ -1672,12 +1708,12 @@ OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
}
template
-OutputIt copy_unit(string_view unit, OutputIt out, Char) {
+auto copy_unit(string_view unit, OutputIt out, Char) -> OutputIt {
return std::copy(unit.begin(), unit.end(), out);
}
template
-OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) {
+auto copy_unit(string_view unit, OutputIt out, wchar_t) -> OutputIt {
// This works when wchar_t is UTF-32 because units only contain characters
// that have the same representation in UTF-16 and UTF-32.
utf8_to_utf16 u(unit);
@@ -1685,7 +1721,7 @@ OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) {
}
template
-OutputIt format_duration_unit(OutputIt out) {
+auto format_duration_unit(OutputIt out) -> OutputIt {
if (const char* unit = get_units())
return copy_unit(string_view(unit), out, Char());
*out++ = '[';
@@ -1752,18 +1788,12 @@ struct chrono_formatter {
// this may overflow and/or the result may not fit in the
// target type.
-#if FMT_SAFE_DURATION_CAST
// might need checked conversion (rep!=Rep)
- auto tmpval = std::chrono::duration(val);
- s = fmt_safe_duration_cast(tmpval);
-#else
- s = std::chrono::duration_cast(
- std::chrono::duration(val));
-#endif
+ s = fmt_duration_cast(std::chrono::duration(val));
}
// returns true if nan or inf, writes to out.
- bool handle_nan_inf() {
+ auto handle_nan_inf() -> bool {
if (isfinite(val)) {
return false;
}
@@ -1780,17 +1810,22 @@ struct chrono_formatter {
return true;
}
- Rep hour() const { return static_cast(mod((s.count() / 3600), 24)); }
+ auto days() const -> Rep { return static_cast(s.count() / 86400); }
+ auto hour() const -> Rep {
+ return static_cast(mod((s.count() / 3600), 24));
+ }
- Rep hour12() const {
+ auto hour12() const -> Rep {
Rep hour = static_cast(mod((s.count() / 3600), 12));
return hour <= 0 ? 12 : hour;
}
- Rep minute() const { return static_cast(mod((s.count() / 60), 60)); }
- Rep second() const { return static_cast(mod(s.count(), 60)); }
+ auto minute() const -> Rep {
+ return static_cast(mod((s.count() / 60), 60));
+ }
+ auto second() const -> Rep { return static_cast(mod(s.count(), 60)); }
- std::tm time() const {
+ auto time() const -> std::tm {
auto time = std::tm();
time.tm_hour = to_nonnegative_int(hour(), 24);
time.tm_min = to_nonnegative_int(minute(), 60);
@@ -1858,10 +1893,14 @@ struct chrono_formatter {
void on_dec0_week_of_year(numeric_system) {}
void on_dec1_week_of_year(numeric_system) {}
void on_iso_week_of_year(numeric_system) {}
- void on_day_of_year() {}
void on_day_of_month(numeric_system) {}
void on_day_of_month_space(numeric_system) {}
+ void on_day_of_year() {
+ if (handle_nan_inf()) return;
+ write(days(), 0);
+ }
+
void on_24_hour(numeric_system ns, pad_type pad) {
if (handle_nan_inf()) return;
@@ -1968,7 +2007,7 @@ class weekday {
weekday() = default;
explicit constexpr weekday(unsigned wd) noexcept
: value(static_cast(wd != 7 ? wd : 0)) {}
- constexpr unsigned c_encoding() const noexcept { return value; }
+ constexpr auto c_encoding() const noexcept -> unsigned { return value; }
};
class year_month_day {};
@@ -2083,25 +2122,22 @@ struct formatter,
period::num != 1 || period::den != 1 ||
std::is_floating_point::value)) {
const auto epoch = val.time_since_epoch();
- auto subsecs = std::chrono::duration_cast(
- epoch - std::chrono::duration_cast(epoch));
+ auto subsecs = detail::fmt_duration_cast(
+ epoch - detail::fmt_duration_cast