diff --git a/README.rst b/README.rst index 32dfb71d..108fd880 100644 --- a/README.rst +++ b/README.rst @@ -81,16 +81,15 @@ Check a format string at compile time: .. code:: c++ // test.cc - #define FMT_STRING_ALIAS 1 #include - std::string s = format(fmt("{2}"), 42); + std::string s = format(FMT_STRING("{2}"), 42); .. code:: $ c++ -Iinclude -std=c++14 test.cc ... test.cc:4:17: note: in instantiation of function template specialization 'fmt::v5::format' requested here - std::string s = format(fmt("{2}"), 42); + std::string s = format(FMT_STRING("{2}"), 42); ^ include/fmt/core.h:778:19: note: non-constexpr function 'on_error' cannot be used in a constant expression ErrorHandler::on_error(message); @@ -122,11 +121,10 @@ Format objects of user-defined types via a simple `extension API template <> struct fmt::formatter { - template - constexpr auto parse(ParseContext &ctx) { return ctx.begin(); } + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template - auto format(const date &d, FormatContext &ctx) { + auto format(const date& d, FormatContext& ctx) { return format_to(ctx.out(), "{}-{}-{}", d.year, d.month, d.day); } }; @@ -142,12 +140,12 @@ which take arbitrary arguments (`godbolt `_): .. code:: c++ // Prints formatted error message. - void vreport_error(const char *format, fmt::format_args args) { + void vreport_error(const char* format, fmt::format_args args) { fmt::print("Error: "); fmt::vprint(format, args); } template - void report_error(const char *format, const Args & ... args) { + void report_error(const char* format, const Args & ... args) { vreport_error(format, fmt::make_format_args(args...)); } @@ -166,15 +164,14 @@ Speed tests ================= ============= =========== Library Method Run Time, s ================= ============= =========== -libc printf 1.01 -libc++ std::ostream 3.04 -{fmt} 1632f72 fmt::print 0.86 -tinyformat 2.0.1 tfm::printf 3.23 -Boost Format 1.67 boost::format 7.98 +libc printf 1.03 +libc++ std::ostream 2.98 +{fmt} 4de41a fmt::print 0.76 +Boost Format 1.67 boost::format 7.24 Folly Format folly::format 2.23 ================= ============= =========== -{fmt} is the fastest of the benchmarked methods, ~17% faster than ``printf``. +{fmt} is the fastest of the benchmarked methods, ~35% faster than ``printf``. The above results were generated by building ``tinyformat_test.cpp`` on macOS 10.14.3 with ``clang++ -O3 -DSPEED_TEST -DHAVE_FORMAT``, and taking the best of @@ -211,7 +208,6 @@ printf 2.6 29 26 printf+string 16.4 29 26 iostreams 31.1 59 55 {fmt} 19.0 37 34 -tinyformat 44.0 103 97 Boost Format 91.9 226 203 Folly Format 115.7 101 88 ============= =============== ==================== ================== @@ -232,14 +228,13 @@ printf 2.2 33 30 printf+string 16.0 33 30 iostreams 28.3 56 52 {fmt} 18.2 59 50 -tinyformat 32.6 88 82 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 and tinyformat are -header-only libraries so they don't provide any linkage options. +compare formatting function overhead only. Boost Format is a +header-only library so it doesn't provide any linkage options. Running the tests ~~~~~~~~~~~~~~~~~ @@ -425,20 +420,6 @@ arguments. However it has significant limitations, citing its author: It is also quite big and has a heavy dependency, STLSoft, which might be too restrictive for using it in some projects. -Loki SafeFormat -~~~~~~~~~~~~~~~ - -SafeFormat is a formatting library which uses ``printf``-like format strings and -is type safe. It doesn't support user-defined types or positional arguments and -makes unconventional use of ``operator()`` for passing format arguments. - -Tinyformat -~~~~~~~~~~ - -This library supports ``printf``-like format strings and is very small . -It doesn't support positional arguments and wrapping it in C++98 is somewhat -difficult. Tinyformat relies on iostreams which limits its performance. - Boost Spirit.Karma ~~~~~~~~~~~~~~~~~~