blob: acddc70ef183f7dd4768d1a14b6a2454a0751dd3 [file] [log] [blame]
Victor Zverovichf1cd5412016-04-24 10:46:21 -07001{fmt}
2=====
vitautec27d5d2012-12-07 08:26:46 -08003
Victor Zverovich5a6a5852016-04-27 08:05:40 -07004.. image:: https://travis-ci.org/fmtlib/fmt.png?branch=master
5 :target: https://travis-ci.org/fmtlib/fmt
Victor Zverovich817d98a2014-04-14 23:19:38 -07006
Victor Zverovichf4b5aea2016-04-27 08:13:56 -07007.. image:: https://ci.appveyor.com/api/projects/status/ehjkiefde6gucy1v
8 :target: https://ci.appveyor.com/project/vitaut/fmt
Victor Zverovichd22d11b2019-05-10 09:54:42 -07009
Victor Zverovich08370c32020-10-17 08:27:21 -070010.. image:: https://oss-fuzz-build-logs.storage.googleapis.com/badges/fmt.svg
Victor Zverovichc0905692020-07-08 08:01:36 -070011 :alt: fmt is continuously fuzzed at oss-fuzz
Victor Zverovich2381df62020-07-04 08:27:57 -070012 :target: https://bugs.chromium.org/p/oss-fuzz/issues/list?\
Victor Zverovich9e208832020-07-04 09:37:27 -070013 colspec=ID%20Type%20Component%20Status%20Proj%20Reported%20Owner%20\
Victor Zverovich37d738f2020-10-16 06:46:39 -070014 Summary&q=proj%3Dfmt&can=1
Paul Dreik840a8172019-09-19 06:47:11 +020015
Victor Zverovich4afb39b2019-11-26 08:33:16 -080016.. image:: https://img.shields.io/badge/stackoverflow-fmt-blue.svg
17 :alt: Ask questions at StackOverflow with the tag fmt
谭九鼎cd2b9902019-12-17 08:48:27 -060018 :target: https://stackoverflow.com/questions/tagged/fmt
Victor Zverovich4afb39b2019-11-26 08:33:16 -080019
Victor Zverovich05a28312020-09-30 17:38:28 -070020**{fmt}** is an open-source formatting library providing a fast and safe
21alternative to C stdio and C++ iostreams.
Victor Zverovich70a23172012-12-07 14:18:37 -080022
Victor Zverovich79ba37f2020-09-26 10:13:04 -070023If you like this project, please consider donating to BYSOL,
24an initiative to help victims of political repressions in Belarus:
Victor Zverovich2213a712020-09-26 11:46:39 -070025https://www.facebook.com/donate/759400044849707/108388587646909/.
Victor Zverovich79ba37f2020-09-26 10:13:04 -070026
Victor Zverovich23063c32020-07-08 07:11:13 -070027`Documentation <https://fmt.dev>`__
vitauteb502692015-05-22 06:50:46 -070028
Victor Zverovichc56cf3d2020-07-04 08:20:10 -070029Q&A: ask questions on `StackOverflow with the tag fmt
30<https://stackoverflow.com/questions/tagged/fmt>`_.
Victor Zverovich4c8efd62019-05-10 09:56:40 -070031
Victor Zverovicha7c5db02020-07-28 08:18:10 -070032Try {fmt} in `Compiler Explorer <https://godbolt.org/z/Eq5763>`_.
Victor Zverovicha4c22ac2020-07-26 12:12:31 -070033
Victor Zverovich70a23172012-12-07 14:18:37 -080034Features
35--------
36
Victor Zverovich8fa20b42020-07-13 06:15:47 -070037* Simple `format API <https://fmt.dev/latest/api.html>`_ with positional arguments
Victor Zverovichc56cf3d2020-07-04 08:20:10 -070038 for localization
39* Implementation of `C++20 std::format
40 <https://en.cppreference.com/w/cpp/utility/format>`__
Victor Zverovich8fa20b42020-07-13 06:15:47 -070041* `Format string syntax <https://fmt.dev/latest/syntax.html>`_ similar to Python's
Victor Zverovichc56cf3d2020-07-04 08:20:10 -070042 `format <https://docs.python.org/3/library/stdtypes.html#str.format>`_
Victor Zverovichf80ed642020-09-14 11:13:51 -070043* Fast IEEE 754 floating-point formatter with correct rounding, shortness and
Victor Zverovich89242112020-10-21 14:02:55 -070044 round-trip guarantees
Victor Zverovich86a7d852015-02-26 09:05:20 -080045* Safe `printf implementation
Victor Zverovich23063c32020-07-08 07:11:13 -070046 <https://fmt.dev/latest/api.html#printf-formatting>`_ including the POSIX
47 extension for positional arguments
48* Extensibility: `support for user-defined types
49 <https://fmt.dev/latest/api.html#formatting-user-defined-types>`_
Victor Zverovichf2301702019-03-10 12:13:14 -070050* High performance: faster than common standard library implementations of
Victor Zverovich23063c32020-07-08 07:11:13 -070051 ``(s)printf``, iostreams, ``to_string`` and ``to_chars``, see `Speed tests`_
52 and `Converting a hundred million integers to strings per second
Victor Zverovich2381df62020-07-04 08:27:57 -070053 <http://www.zverovich.net/2020/06/13/fast-int-to-string-revisited.html>`_
Victor Zverovich23063c32020-07-08 07:11:13 -070054* Small code size both in terms of source code with the minimum configuration
55 consisting of just three files, ``core.h``, ``format.h`` and ``format-inl.h``,
56 and compiled code; see `Compile time and code bloat`_
Victor Zveroviche4c954f2020-08-07 16:03:15 -070057* Reliability: the library has an extensive set of `tests
58 <https://github.com/fmtlib/fmt/tree/master/test>`_ and is `continuously fuzzed
Victor Zverovich1378dda2020-08-08 18:01:56 -070059 <https://bugs.chromium.org/p/oss-fuzz/issues/list?colspec=ID%20Type%20
Victor Zverovich37d738f2020-10-16 06:46:39 -070060 Component%20Status%20Proj%20Reported%20Owner%20Summary&q=proj%3Dfmt&can=1>`_
Victor Zveroviche613b3c2017-11-10 07:24:16 -080061* Safety: the library is fully type safe, errors in format strings can be
62 reported at compile time, automatic memory management prevents buffer overflow
Victor Zverovichc56cf3d2020-07-04 08:20:10 -070063 errors
Victor Zverovich7c697bf2012-12-11 16:30:27 -080064* Ease of use: small self-contained code base, no external dependencies,
Victor Zverovich972ffd32019-09-06 13:13:30 -070065 permissive MIT `license
Victor Zveroviche817bb92016-04-27 08:23:03 -070066 <https://github.com/fmtlib/fmt/blob/master/LICENSE.rst>`_
Victor Zverovich91bb3aa2019-05-17 15:42:00 -070067* `Portability <https://fmt.dev/latest/index.html#portability>`_ with
Victor Zverovichc56cf3d2020-07-04 08:20:10 -070068 consistent output across platforms and support for older compilers
Victor Zverovich23063c32020-07-08 07:11:13 -070069* Clean warning-free codebase even on high warning levels such as
70 ``-Wall -Wextra -pedantic``
Victor Zverovichc56cf3d2020-07-04 08:20:10 -070071* Locale-independence by default
Victor Zverovichc56cf3d2020-07-04 08:20:10 -070072* Optional header-only configuration enabled with the ``FMT_HEADER_ONLY`` macro
Victor Zverovich70a23172012-12-07 14:18:37 -080073
Victor Zverovich23063c32020-07-08 07:11:13 -070074See the `documentation <https://fmt.dev>`_ for more details.
Victor Zverovichc7354b62013-01-21 10:11:59 -080075
Victor Zverovich58e53b42012-12-07 14:32:48 -080076Examples
77--------
Victor Zverovich70a23172012-12-07 14:18:37 -080078
Victor Zverovichc2399cc2020-07-28 08:21:04 -070079**Print to stdout** (`run <https://godbolt.org/z/Tevcjh>`_)
Victor Zverovichf02e4102014-11-07 07:04:03 -080080
81.. code:: c++
Victor Zverovich58e53b42012-12-07 14:32:48 -080082
Victor Zverovich0b3a83f2020-06-20 05:37:58 -070083 #include <fmt/core.h>
84
85 int main() {
86 fmt::print("Hello, world!\n");
87 }
Victor Zverovichc50f94a2012-12-07 13:20:50 -080088
Victor Zverovich2a47a1e2020-08-01 12:00:01 -070089**Format a string** (`run <https://godbolt.org/z/oK8h33>`_)
Victor Zverovich4faec5a2020-07-05 06:41:51 -070090
91.. code:: c++
92
93 std::string s = fmt::format("The answer is {}.", 42);
94 // s == "The answer is 42."
95
Victor Zverovich0b6e7cc2020-08-03 21:51:48 -070096**Format a string using positional arguments** (`run <https://godbolt.org/z/Yn7Txe>`_)
Victor Zverovich0fa65cf2019-03-16 07:36:27 -070097
98.. code:: c++
99
100 std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
Victor Zverovich9b392a62019-03-16 07:59:58 -0700101 // s == "I'd rather be happy than right."
Victor Zverovich0fa65cf2019-03-16 07:36:27 -0700102
Victor Zverovich64e2da12020-07-28 08:35:28 -0700103**Print chrono durations** (`run <https://godbolt.org/z/K8s4Mc>`_)
Victor Zverovich4faec5a2020-07-05 06:41:51 -0700104
105.. code:: c++
106
107 #include <fmt/chrono.h>
108
109 int main() {
Victor Zverovich23063c32020-07-08 07:11:13 -0700110 using namespace std::literals::chrono_literals;
111 fmt::print("Default format: {} {}\n", 42s, 100ms);
112 fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);
Victor Zverovich4faec5a2020-07-05 06:41:51 -0700113 }
114
Victor Zverovich0c1f4b52020-07-26 10:57:59 -0700115Output::
Victor Zverovich23063c32020-07-08 07:11:13 -0700116
117 Default format: 42s 100ms
118 strftime-like format: 03:15:30
Victor Zverovich4faec5a2020-07-05 06:41:51 -0700119
Victor Zverovichd7921d62020-08-06 19:41:17 -0700120**Print a container** (`run <https://godbolt.org/z/MjsY7c>`_)
Victor Zverovichc4ad94c2020-07-08 18:17:26 -0700121
122.. code:: c++
123
Victor Zverovichc5adfc52020-07-09 06:21:02 -0700124 #include <vector>
Victor Zverovichc4ad94c2020-07-08 18:17:26 -0700125 #include <fmt/ranges.h>
126
127 int main() {
128 std::vector<int> v = {1, 2, 3};
129 fmt::print("{}\n", v);
130 }
131
Victor Zverovich0c1f4b52020-07-26 10:57:59 -0700132Output::
Victor Zverovichc4ad94c2020-07-08 18:17:26 -0700133
134 {1, 2, 3}
135
Victor Zverovich0c1f4b52020-07-26 10:57:59 -0700136**Check a format string at compile time**
Victor Zverovichdba1ccc2017-11-10 07:38:51 -0800137
138.. code:: c++
139
Victor Zverovich1efdb2d2020-07-08 07:47:18 -0700140 std::string s = fmt::format(FMT_STRING("{:d}"), "don't panic");
Victor Zverovichdc69afa2020-07-08 07:44:36 -0700141
Victor Zverovich1efdb2d2020-07-08 07:47:18 -0700142This gives a compile-time error because ``d`` is an invalid format specifier for
143a string.
Victor Zverovich1a236c82013-09-06 15:12:46 -0700144
Victor Zverovich0c1f4b52020-07-26 10:57:59 -0700145**Write a file from a single thread**
Victor Zverovich5f629542020-07-12 09:55:24 -0700146
147.. code:: c++
148
149 #include <fmt/os.h>
150
151 int main() {
152 auto out = fmt::output_file("guide.txt");
153 out.print("Don't {}", "Panic");
154 }
155
Victor Zverovich2f8fc292020-08-05 10:53:49 -0700156This can be `5 to 9 times faster than fprintf
157<http://www.zverovich.net/2020/08/04/optimal-file-buffer-size.html>`_.
Victor Zverovich5f629542020-07-12 09:55:24 -0700158
Victor Zveroviche2c8c452020-08-07 20:58:29 -0700159**Print with colors and text styles**
Victor Zverovich0a7032a2020-07-26 08:14:18 -0700160
161.. code:: c++
162
163 #include <fmt/color.h>
164
165 int main() {
166 fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,
167 "Hello, {}!\n", "world");
168 fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
169 fmt::emphasis::underline, "Hello, {}!\n", "мир");
170 fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
171 "Hello, {}!\n", "世界");
172 }
173
Victor Zverovich1378dda2020-08-08 18:01:56 -0700174Output on a modern terminal:
Victor Zverovich0a7032a2020-07-26 08:14:18 -0700175
176.. image:: https://user-images.githubusercontent.com/
Victor Zverovich63b422e2020-07-26 10:37:00 -0700177 576385/88485597-d312f600-cf2b-11ea-9cbe-61f535a86e28.png
Victor Zverovich0a7032a2020-07-26 08:14:18 -0700178
Victor Zverovichfdd01492019-03-16 07:27:53 -0700179Benchmarks
180----------
181
182Speed tests
183~~~~~~~~~~~
184
185================= ============= ===========
186Library Method Run Time, s
187================= ============= ===========
Victor Zverovich5916ff62019-12-07 10:12:15 -0800188libc printf 1.04
189libc++ std::ostream 3.05
Victor Zverovich95dfdc62019-12-07 10:12:56 -0800190{fmt} 6.1.1 fmt::print 0.75
Victor Zverovichf4fcc5f2019-11-20 09:31:11 -0800191Boost Format 1.67 boost::format 7.24
Victor Zverovichfdd01492019-03-16 07:27:53 -0700192Folly Format folly::format 2.23
193================= ============= ===========
194
Victor Zverovichf4fcc5f2019-11-20 09:31:11 -0800195{fmt} is the fastest of the benchmarked methods, ~35% faster than ``printf``.
Victor Zverovichfdd01492019-03-16 07:27:53 -0700196
197The above results were generated by building ``tinyformat_test.cpp`` on macOS
Victor Zverovichc56cf3d2020-07-04 08:20:10 -070019810.14.6 with ``clang++ -O3 -DNDEBUG -DSPEED_TEST -DHAVE_FORMAT``, and taking the
199best of three runs. In the test, the format string ``"%0.10f:%04d:%+g:%s:%p:%c:%%\n"``
Victor Zverovichfdd01492019-03-16 07:27:53 -0700200or equivalent is filled 2,000,000 times with output sent to ``/dev/null``; for
201further details refer to the `source
202<https://github.com/fmtlib/format-benchmark/blob/master/tinyformat_test.cpp>`_.
203
Victor Zverovich5eb292a2020-10-11 09:57:21 -0700204{fmt} is up to 20-30x faster than ``std::ostringstream`` and ``sprintf`` on
Victor Zverovichc56cf3d2020-07-04 08:20:10 -0700205floating-point formatting (`dtoa-benchmark <https://github.com/fmtlib/dtoa-benchmark>`_)
Victor Zverovich5eb292a2020-10-11 09:57:21 -0700206and faster than `double-conversion <https://github.com/google/double-conversion>`_ and
207`ryu <https://github.com/ulfjack/ryu>`_:
Victor Zverovich0a66e4c2019-03-24 11:37:07 -0700208
Victor Zverovichc1429652020-07-08 13:34:47 -0700209.. image:: https://user-images.githubusercontent.com/576385/
Victor Zverovich5eb292a2020-10-11 09:57:21 -0700210 95684665-11719600-0ba8-11eb-8e5b-972ff4e49428.png
211 :target: https://fmt.dev/unknown_mac64_clang12.0.html
Victor Zverovich0a66e4c2019-03-24 11:37:07 -0700212
Victor Zverovichfdd01492019-03-16 07:27:53 -0700213Compile time and code bloat
214~~~~~~~~~~~~~~~~~~~~~~~~~~~
215
216The script `bloat-test.py
217<https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py>`_
218from `format-benchmark <https://github.com/fmtlib/format-benchmark>`_
219tests compile time and code bloat for nontrivial projects.
220It generates 100 translation units and uses ``printf()`` or its alternative
221five times in each to simulate a medium sized project. The resulting
222executable size and compile time (Apple LLVM version 8.1.0 (clang-802.0.42),
223macOS Sierra, best of three) is shown in the following tables.
224
225**Optimized build (-O3)**
226
227============= =============== ==================== ==================
228Method Compile Time, s Executable size, KiB Stripped size, KiB
229============= =============== ==================== ==================
230printf 2.6 29 26
231printf+string 16.4 29 26
232iostreams 31.1 59 55
233{fmt} 19.0 37 34
Victor Zverovichfdd01492019-03-16 07:27:53 -0700234Boost Format 91.9 226 203
235Folly Format 115.7 101 88
236============= =============== ==================== ==================
237
238As you can see, {fmt} has 60% less overhead in terms of resulting binary code
239size compared to iostreams and comes pretty close to ``printf``. Boost Format
240and Folly Format have the largest overheads.
241
242``printf+string`` is the same as ``printf`` but with extra ``<string>``
243include to measure the overhead of the latter.
244
245**Non-optimized build**
246
247============= =============== ==================== ==================
248Method Compile Time, s Executable size, KiB Stripped size, KiB
249============= =============== ==================== ==================
250printf 2.2 33 30
251printf+string 16.0 33 30
252iostreams 28.3 56 52
253{fmt} 18.2 59 50
Victor Zverovichfdd01492019-03-16 07:27:53 -0700254Boost Format 54.1 365 303
255Folly Format 79.9 445 430
256============= =============== ==================== ==================
257
258``libc``, ``lib(std)c++`` and ``libfmt`` are all linked as shared libraries to
Victor Zverovich6793ffc2019-11-20 09:33:59 -0800259compare formatting function overhead only. Boost Format is a
260header-only library so it doesn't provide any linkage options.
Victor Zverovichfdd01492019-03-16 07:27:53 -0700261
262Running the tests
263~~~~~~~~~~~~~~~~~
264
265Please refer to `Building the library`__ for the instructions on how to build
266the library and run the unit tests.
267
Victor Zverovich91bb3aa2019-05-17 15:42:00 -0700268__ https://fmt.dev/latest/usage.html#building-the-library
Victor Zverovichfdd01492019-03-16 07:27:53 -0700269
270Benchmarks reside in a separate repository,
271`format-benchmarks <https://github.com/fmtlib/format-benchmark>`_,
272so to run the benchmarks you first need to clone this repository and
273generate Makefiles with CMake::
274
275 $ git clone --recursive https://github.com/fmtlib/format-benchmark.git
276 $ cd format-benchmark
277 $ cmake .
278
279Then you can run the speed test::
280
281 $ make speed-test
282
283or the bloat test::
284
285 $ make bloat-test
286
Victor Zverovichaffa7942014-01-30 11:16:27 -0800287Projects using this library
288---------------------------
289
Victor Zverovich71e705a2020-10-19 08:54:55 -0700290* `0 A.D. <https://play0ad.com/>`_: a free, open-source, cross-platform
Victor Zverovich813732f2020-04-22 06:07:12 -0700291 real-time strategy game
Victor Zverovich38a74062015-02-06 13:46:19 -0800292
Victor Zverovich73ec6502014-10-12 14:18:17 -0700293* `AMPL/MP <https://github.com/ampl/mp>`_:
Victor Zverovich71e705a2020-10-19 08:54:55 -0700294 an open-source library for mathematical programming
Victor Zverovich8603bd22020-06-11 17:25:20 -0700295
296* `Aseprite <https://github.com/aseprite/aseprite>`_:
Victor Zverovich71e705a2020-10-19 08:54:55 -0700297 animated sprite editor & pixel art tool
Victor Zverovich8603bd22020-06-11 17:25:20 -0700298
Victor Zverovich71e705a2020-10-19 08:54:55 -0700299* `AvioBook <https://www.aviobook.aero/en>`_: a comprehensive aircraft
Victor Zverovicha0844952018-11-28 17:28:27 -0800300 operations suite
Victor Zverovich29352af2018-12-01 08:19:20 -0800301
Victor Zverovich71e705a2020-10-19 08:54:55 -0700302* `Blizzard Battle.net <https://battle.net/>`_: an online gaming platform
303
304* `Celestia <https://celestia.space/>`_: real-time 3D visualization of space
Victor Zverovichaffa7942014-01-30 11:16:27 -0800305
Victor Zverovich71e705a2020-10-19 08:54:55 -0700306* `Ceph <https://ceph.com/>`_: a scalable distributed storage system
Victor Zverovicha0844952018-11-28 17:28:27 -0800307
Victor Zverovich71e705a2020-10-19 08:54:55 -0700308* `ccache <https://ccache.dev/>`_: a compiler cache
Victor Zverovich58a8f2f2019-09-06 06:26:09 -0700309
Victor Zverovich445f5d32020-07-08 07:36:07 -0700310* `ClickHouse <https://github.com/ClickHouse/ClickHouse>`_: analytical database
311 management system
alexey-milovidov90475482020-07-05 15:57:04 +0300312
Victor Zverovicha0844952018-11-28 17:28:27 -0800313* `CUAUV <http://cuauv.org/>`_: Cornell University's autonomous underwater
314 vehicle
Victor Zverovich2bf59a92016-08-10 08:29:44 -0700315
Victor Zverovich71e705a2020-10-19 08:54:55 -0700316* `Drake <https://drake.mit.edu/>`_: a planning, control, and analysis toolbox
Victor Zverovich813732f2020-04-22 06:07:12 -0700317 for nonlinear dynamical systems (MIT)
318
319* `Envoy <https://lyft.github.io/envoy/>`_: C++ L7 proxy and communication bus
320 (Lyft)
321
322* `FiveM <https://fivem.net/>`_: a modification framework for GTA V
323
Victor Zverovich8a111482020-04-22 06:16:07 -0700324* `Folly <https://github.com/facebook/folly>`_: Facebook open-source library
325
vitaut7e94fcb2015-12-03 08:09:53 -0800326* `HarpyWar/pvpgn <https://github.com/pvpgn/pvpgn-server>`_:
Victor Zverovich8dbfd722014-06-28 19:17:13 -0700327 Player vs Player Gaming Network with tweaks
328
Victor Zverovich71e705a2020-10-19 08:54:55 -0700329* `KBEngine <https://github.com/kbengine/kbengine>`_: an open-source MMOG server
Victor Zverovichc0905692020-07-08 08:01:36 -0700330 engine
Victor Zverovich2938a922014-09-13 08:44:49 -0700331
Victor Zverovich71e705a2020-10-19 08:54:55 -0700332* `Keypirinha <https://keypirinha.com/>`_: a semantic launcher for Windows
Victor Zverovich090de292016-03-10 10:51:52 -0800333
Victor Zverovich71e705a2020-10-19 08:54:55 -0700334* `Kodi <https://kodi.tv/>`_ (formerly xbmc): home theater software
Victor Zverovicha09f7482018-01-27 17:47:41 -0800335
Victor Zverovich71e705a2020-10-19 08:54:55 -0700336* `Knuth <https://kth.cash/>`_: high-performance Bitcoin full-node
Fernando Pelliccionif2303002020-05-19 22:08:32 -0300337
Victor Zverovich8603bd22020-06-11 17:25:20 -0700338* `Microsoft Verona <https://github.com/microsoft/verona>`_:
Victor Zverovich71e705a2020-10-19 08:54:55 -0700339 research programming language for concurrent ownership
Victor Zverovich73ec6502014-10-12 14:18:17 -0700340
Victor Zverovich71e705a2020-10-19 08:54:55 -0700341* `MongoDB <https://mongodb.com/>`_: distributed document database
Billy Donahue1763d0e2019-04-12 12:47:21 -0400342
Victor Zverovich71e705a2020-10-19 08:54:55 -0700343* `MongoDB Smasher <https://github.com/duckie/mongo_smasher>`_: a small tool to
Victor Zverovichc57029c2018-02-01 16:44:27 -0800344 generate randomized datasets
Victor Zverovich6e820842016-03-01 14:28:52 -0800345
Victor Zverovich71e705a2020-10-19 08:54:55 -0700346* `OpenSpace <https://openspaceproject.com/>`_: an open-source
Victor Zverovich813732f2020-04-22 06:07:12 -0700347 astrovisualization framework
Victor Zverovich1a7d0ba2018-02-02 19:10:25 -0800348
谭九鼎cd2b9902019-12-17 08:48:27 -0600349* `PenUltima Online (POL) <https://www.polserver.com/>`_:
Victor Zverovich71e705a2020-10-19 08:54:55 -0700350 an MMO server, compatible with most Ultima Online clients
Victor Zverovich81dc04d2015-02-07 08:31:17 -0800351
Victor Zverovich71e705a2020-10-19 08:54:55 -0700352* `PyTorch <https://github.com/pytorch/pytorch>`_: an open-source machine
Victor Zverovich44b65842020-05-01 10:39:28 -0700353 learning library
354
Victor Zverovich71e705a2020-10-19 08:54:55 -0700355* `quasardb <https://www.quasardb.net/>`_: a distributed, high-performance,
Victor Zverovich1a7d0ba2018-02-02 19:10:25 -0800356 associative database
Victor Zverovich16985fd2020-08-09 08:56:51 -0700357
Victor Zverovich71e705a2020-10-19 08:54:55 -0700358* `Quill <https://github.com/odygrd/quill>`_: asynchronous low-latency logging library
Victor Zverovich001054c2015-04-27 07:02:15 -0700359
Victor Zverovich71e705a2020-10-19 08:54:55 -0700360* `QKW <https://github.com/ravijanjam/qkw>`_: generalizing aliasing to simplify
Victor Zverovichd5b80022020-09-21 09:40:49 -0700361 navigation, and executing complex multi-line terminal command sequences
Ravi J821471e2020-09-21 11:39:07 -0500362
Victor Zverovich71e705a2020-10-19 08:54:55 -0700363* `redis-cerberus <https://github.com/HunanTV/redis-cerberus>`_: a Redis cluster
Victor Zverovicha0844952018-11-28 17:28:27 -0800364 proxy
Victor Zverovich42d8f5b2015-09-16 21:33:51 -0700365
Victor Zverovich71e705a2020-10-19 08:54:55 -0700366* `redpanda <https://vectorized.io/redpanda>`_: a 10x faster Kafka® replacement
Victor Zveroviche371e8b2020-04-22 06:13:36 -0700367 for mission critical systems written in C++
Alexander Gallego3670d5b2020-04-21 18:44:14 -0700368
Victor Zverovich71e705a2020-10-19 08:54:55 -0700369* `rpclib <http://rpclib.net/>`_: a modern C++ msgpack-RPC server and client
Victor Zverovichb10ccb82018-12-05 06:42:33 -0800370 library
371
Victor Zverovich813732f2020-04-22 06:07:12 -0700372* `Salesforce Analytics Cloud
373 <https://www.salesforce.com/analytics-cloud/overview/>`_:
Victor Zverovich71e705a2020-10-19 08:54:55 -0700374 business intelligence software
Victor Zverovicha23fbbb2014-12-02 12:54:12 -0800375
Victor Zverovich71e705a2020-10-19 08:54:55 -0700376* `Scylla <https://www.scylladb.com/>`_: a Cassandra-compatible NoSQL data store
Victor Zverovicha0844952018-11-28 17:28:27 -0800377 that can handle 1 million transactions per second on a single server
Victor Zverovich2bf59a92016-08-10 08:29:44 -0700378
Victor Zverovich71e705a2020-10-19 08:54:55 -0700379* `Seastar <http://www.seastar-project.org/>`_: an advanced, open-source C++
Victor Zverovicha0844952018-11-28 17:28:27 -0800380 framework for high-performance server applications on modern hardware
Victor Zverovich2bf59a92016-08-10 08:29:44 -0700381
Victor Zverovich71e705a2020-10-19 08:54:55 -0700382* `spdlog <https://github.com/gabime/spdlog>`_: super fast C++ logging library
Victor Zverovich6e3d7d92014-12-08 06:15:31 -0800383
Victor Zverovich71e705a2020-10-19 08:54:55 -0700384* `Stellar <https://www.stellar.org/>`_: financial platform
Victor Zverovicha12f4962015-09-16 21:45:27 -0700385
Victor Zverovich71e705a2020-10-19 08:54:55 -0700386* `Touch Surgery <https://www.touchsurgery.com/>`_: surgery simulator
vitaut32fbc082015-08-08 18:58:25 -0700387
Victor Zverovich71e705a2020-10-19 08:54:55 -0700388* `TrinityCore <https://github.com/TrinityCore/TrinityCore>`_: open-source
Victor Zverovicha0844952018-11-28 17:28:27 -0800389 MMORPG framework
Victor Zverovichef5972e2015-03-17 19:43:47 -0700390
Victor Zverovich71e705a2020-10-19 08:54:55 -0700391* `Windows Terminal <https://github.com/microsoft/terminal>`_: the new Windows
392 terminal
Victor Zverovich9e2ad7c2020-04-21 15:47:04 -0700393
Victor Zverovich2ed412f2019-09-06 13:03:14 -0700394`More... <https://github.com/search?q=fmtlib&type=Code>`_
Victor Zverovichd930f692015-02-06 14:03:44 -0800395
Victor Zverovich9d590572014-06-29 11:51:27 -0700396If you are aware of other projects using this library, please let me know
Victor Zverovich73ec6502014-10-12 14:18:17 -0700397by `email <mailto:victor.zverovich@gmail.com>`_ or by submitting an
Victor Zveroviche817bb92016-04-27 08:23:03 -0700398`issue <https://github.com/fmtlib/fmt/issues>`_.
Victor Zverovichaffa7942014-01-30 11:16:27 -0800399
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800400Motivation
401----------
402
403So why yet another formatting library?
404
405There are plenty of methods for doing this task, from standard ones like
Victor Zverovich1428b342019-03-16 06:30:50 -0700406the printf family of function and iostreams to Boost Format and FastFormat
Victor Zverovich5e5506f2019-03-12 06:08:18 -0700407libraries. The reason for creating a new library is that every existing
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800408solution that I found either had serious issues or didn't provide
409all the features I needed.
410
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700411printf
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800412~~~~~~
413
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700414The good thing about ``printf`` is that it is pretty fast and readily available
Victor Zveroviche1ba41f2014-05-14 19:17:20 -0700415being a part of the C standard library. The main drawback is that it
Victor Zverovichef392742019-03-16 06:47:18 -0700416doesn't support user-defined types. ``printf`` also has safety issues although
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700417they are somewhat mitigated with `__attribute__ ((format (printf, ...))
谭九鼎cd2b9902019-12-17 08:48:27 -0600418<https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>`_ in GCC.
Victor Zverovichcb458292012-12-09 10:09:15 -0800419There is a POSIX extension that adds positional arguments required for
vitaut7e94fcb2015-12-03 08:09:53 -0800420`i18n <https://en.wikipedia.org/wiki/Internationalization_and_localization>`_
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700421to ``printf`` but it is not a part of C99 and may not be available on some
Victor Zverovichcb458292012-12-09 10:09:15 -0800422platforms.
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800423
Victor Zverovich1428b342019-03-16 06:30:50 -0700424iostreams
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800425~~~~~~~~~
426
Victor Zverovich1428b342019-03-16 06:30:50 -0700427The main issue with iostreams is best illustrated with an example:
Victor Zverovicha8a536b2012-12-13 08:12:09 -0800428
Victor Zverovichf02e4102014-11-07 07:04:03 -0800429.. code:: c++
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800430
431 std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n";
432
Victor Zverovicha8a536b2012-12-13 08:12:09 -0800433which is a lot of typing compared to printf:
434
Victor Zverovichf02e4102014-11-07 07:04:03 -0800435.. code:: c++
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800436
437 printf("%.2f\n", 1.23456);
438
Victor Zverovich1428b342019-03-16 06:30:50 -0700439Matthew Wilson, the author of FastFormat, called this "chevron hell". iostreams
440don't support positional arguments by design.
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800441
Victor Zverovich1428b342019-03-16 06:30:50 -0700442The good part is that iostreams support user-defined types and are safe although
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700443error handling is awkward.
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800444
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700445Boost Format
446~~~~~~~~~~~~
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800447
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700448This is a very powerful library which supports both ``printf``-like format
449strings and positional arguments. Its main drawback is performance. According to
Victor Zverovichc0905692020-07-08 08:01:36 -0700450various, benchmarks it is much slower than other methods considered here. Boost
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700451Format also has excessive build times and severe code bloat issues (see
452`Benchmarks`_).
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800453
454FastFormat
455~~~~~~~~~~
456
Victor Zverovichc56cf3d2020-07-04 08:20:10 -0700457This is an interesting library which is fast, safe and has positional arguments.
458However, it has significant limitations, citing its author:
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800459
460 Three features that have no hope of being accommodated within the
461 current design are:
462
463 * Leading zeros (or any other non-space padding)
464 * Octal/hexadecimal encoding
465 * Runtime width/alignment specification
466
Victor Zverovichc56cf3d2020-07-04 08:20:10 -0700467It is also quite big and has a heavy dependency, STLSoft, which might be too
468restrictive for using it in some projects.
Victor Zverovich3e4d8472012-12-07 15:33:27 -0800469
Victor Zverovich3cea8692012-12-24 21:31:05 -0800470Boost Spirit.Karma
471~~~~~~~~~~~~~~~~~~
472
Victor Zverovicha7f68dc2019-03-16 06:46:19 -0700473This is not really a formatting library but I decided to include it here for
474completeness. As iostreams, it suffers from the problem of mixing verbatim text
475with arguments. The library is pretty fast, but slower on integer formatting
Victor Zverovichc56cf3d2020-07-04 08:20:10 -0700476than ``fmt::format_to`` with format string compilation on Karma's own benchmark,
477see `Converting a hundred million integers to strings per second
478<http://www.zverovich.net/2020/06/13/fast-int-to-string-revisited.html>`_.
Victor Zverovich8bbb0b42018-08-15 06:34:34 -0700479
Victor Zverovichfaccb4c2012-12-12 07:44:41 -0800480License
481-------
482
Victor Zverovich972ffd32019-09-06 13:13:30 -0700483{fmt} is distributed under the MIT `license
Victor Zveroviche817bb92016-04-27 08:23:03 -0700484<https://github.com/fmtlib/fmt/blob/master/LICENSE.rst>`_.
Victor Zveroviche7c7b122013-01-14 06:43:31 -0800485
Victor Zverovichc56cf3d2020-07-04 08:20:10 -0700486Documentation License
487---------------------
Victor Zveroviche7c7b122013-01-14 06:43:31 -0800488
Victor Zverovichc56cf3d2020-07-04 08:20:10 -0700489The `Format String Syntax <https://fmt.dev/latest/syntax.html>`_
490section in the documentation is based on the one from Python `string module
491documentation <https://docs.python.org/3/library/string.html#module-string>`_.
492For this reason the documentation is distributed under the Python Software
493Foundation license available in `doc/python-license.txt
494<https://raw.github.com/fmtlib/fmt/master/doc/python-license.txt>`_.
495It only applies if you distribute the documentation of {fmt}.
496
497Maintainers
498-----------
Victor Zverovichc50f94a2012-12-07 13:20:50 -0800499
Victor Zverovichfdd01492019-03-16 07:27:53 -0700500The {fmt} library is maintained by Victor Zverovich (`vitaut
Victor Zverovich38b603a2018-01-20 17:12:43 -0800501<https://github.com/vitaut>`_) and Jonathan Müller (`foonathan
502<https://github.com/foonathan>`_) with contributions from many other people.
503See `Contributors <https://github.com/fmtlib/fmt/graphs/contributors>`_ and
504`Releases <https://github.com/fmtlib/fmt/releases>`_ for some of the names.
505Let us know if your contribution is not listed or mentioned incorrectly and
506we'll make it right.