Releases: fmtlib/fmt
10.0.0
-
Replaced Grisu with a new floating-point formatting algorithm for given precision (#3262, #2750, #3269, #3276). The new algorithm is based on Dragonbox already used for the shortest representation and gives substantial performance improvement:
-
Red: new algorithm
-
Green: new algorithm with
FMT_USE_FULL_CACHE_DRAGONBOX
defined to 1 -
Blue: old algorithm
Thanks @jk-jeon (Junekey Jeon).
-
-
Replaced
snprintf
-based hex float formatter with an internal implementation (#3179, #3203). This removes the last usage ofs(n)printf
in {fmt}. Thanks @phprus (Vladislav Shchapov). -
Fixed alignment of floating-point numbers with localization (#3263, #3272). Thanks @ShawnZhong (Shawn Zhong).
-
Made handling of
#
consistent withstd::format
. -
Improved C++20 module support (#3134, #3254, #3386, #3387, #3388, #3392, #3397, #3399, #3400). Thanks @laitingsheng (Tinson Lai), @Orvid (Orvid King), @DanielaE (Daniela Engert). Switched to the modules CMake library which allows building {fmt} as a C++20 module with clang:
CXX=clang++ cmake -DFMT_MODULE=ON . make
-
Made
format_as
work with any user-defined type and not just enums. For example (godbolt):#include <fmt/format.h> struct floaty_mc_floatface { double value; }; auto format_as(floaty_mc_floatface f) { return f.value; } int main() { fmt::print("{:8}\n", floaty_mc_floatface{0.42}); // prints " 0.42" }
-
Removed deprecated implicit conversions for enums and conversions to primitive types for compatibility with
std::format
and to prevent potential ODR violations. Useformat_as
instead. -
Added support for fill, align and width to the time point formatter (#3237, #3260, #3275). For example (godbolt):
#include <fmt/chrono.h> int main() { // prints " 2023" fmt::print("{:>8%Y}\n", std::chrono::system_clock::now()); }
Thanks @ShawnZhong (Shawn Zhong).
-
Implemented formatting of subseconds (#2207, #3117, #3115, #3143, #3144, #3349). For example (godbolt):
#include <fmt/chrono.h> int main() { // prints 01.234567 fmt::print("{:%S}\n", std::chrono::microseconds(1234567)); }
Thanks @patrickroocks (Patrick Roocks) @phprus (Vladislav Shchapov), @BRevzin (Barry Revzin).
-
Added precision support to
%S
(#3148). Thanks @SappyJoy (Stepan Ponomaryov) -
Added support for
std::utc_time
(#3098, #3110). Thanks @patrickroocks (Patrick Roocks). -
Switched formatting of
std::chrono::system_clock
from local time to UTC for compatibility with the standard (#3199, #3230). Thanks @ned14 (Niall Douglas). -
Added support for
%Ez
and%Oz
to chrono formatters. (#3220, #3222). Thanks @phprus (Vladislav Shchapov). -
Improved validation of format specifiers for
std::chrono::duration
(#3219, #3232). Thanks @ShawnZhong (Shawn Zhong). -
Fixed formatting of time points before the epoch (#3117, #3261). For example (godbolt):
#include <fmt/chrono.h> int main() { auto t = std::chrono::system_clock::from_time_t(0) - std::chrono::milliseconds(250); fmt::print("{:%S}\n", t); // prints 59.750000000 }
Thanks @ShawnZhong (Shawn Zhong).
-
Experimental: implemented glibc extension for padding seconds, minutes and hours (#2959, #3271). Thanks @ShawnZhong (Shawn Zhong).
-
Added a formatter for
std::exception
(#2977, #3012, #3062, #3076, #3119). For example (godbolt):#include <fmt/std.h> #include <vector> int main() { try { std::vector<bool>().at(0); } catch(const std::exception& e) { fmt::print("{}", e); } }
prints:
vector<bool>::_M_range_check: __n (which is 0) >= this->size() (which is 0)
on libstdc++. Thanks @zach2good (Zach Toogood) and @phprus (Vladislav Shchapov).
-
Moved
std::error_code
formatter fromfmt/os.h
tofmt/std.h
. (#3125). Thanks @phprus (Vladislav Shchapov). -
Added formatters for standard container adapters:
std::priority_queue
,std::queue
andstd::stack
(#3215, #3279). For example (godbolt):#include <fmt/ranges.h> #include <stack> #include <vector> int main() { auto s = std::stack<bool, std::vector<bool>>(); for (auto b: {true, false, true}) s.push(b); fmt::print("{}\n", s); // prints [true, false, true] }
Thanks @ShawnZhong (Shawn Zhong).
-
Added a formatter for
std::optional
tofmt/std.h
. Thanks @tom-huntington. -
Fixed formatting of valueless by exception variants (#3347). Thanks @TheOmegaCarrot.
-
Made
fmt::ptr
acceptunique_ptr
with a custom deleter (#3177). Thanks @hmbj (Hans-Martin B. Jensen). -
Fixed formatting of noncopyable ranges and nested ranges of chars (#3158 #3286, #3290). Thanks @BRevzin (Barry Revzin).
-
Fixed issues with formatting of paths and ranges of paths (#3319, #3321 #3322). Thanks @phprus (Vladislav Shchapov).
-
Improved handling of invalid Unicode in paths.
-
Enabled compile-time checks on Apple clang 14 and later (#3331). Thanks @cloyce (Cloyce D. Spradling).
-
Improved compile-time checks of named arguments (#3105, #3214). Thanks @rbrich (Radek Brich).
-
Fixed formatting when both alignment and
0
are given (#3236, #3248). Thanks @ShawnZhong (Shawn Zhong). -
Improved Unicode support in the experimental file API on Windows (#3234, #3293). Thanks @Fros1er (Froster).
-
Unified UTF transcoding (#3416). Thanks @phprus (Vladislav Shchapov).
-
Added support for UTF-8 digit separators via an experimental locale facet (#1861). For example (godbolt):
auto loc = std::locale( std::locale(), new fmt::format_facet<std::locale>("’")); auto s = fmt::format(loc, "{:L}", 1000);
where
’
is U+2019 used as a digit separator in the de_CH locale. -
Added an overload of
formatted_size
that takes a locale (#3084, #3087). Thanks @gerboengels. -
Removed the deprecated
FMT_DEPRECATED_OSTREAM
. -
Fixed a UB when using a null
std::string_view
withfmt::to_string
or format string compilation (#3241, #3244). Thanks @phprus (Vladislav Shchapov). -
Added
starts_with
to the fallbackstring_view
implementation (#3080). Thanks @phprus (Vladislav Shchapov). -
Added
fmt::basic_format_string::get()
for compatibility withbasic_format_string
(#3111). Thanks @huangqinjin. -
Added
println
for compatibility with C++23 (#3267). Thanks @ShawnZhong (Shawn Zhong). -
Renamed the
FMT_EXPORT
macro for shared library usage toFMT_LIB_EXPORT
. -
Improved documentation (#3108, #3169, #3243). #3404). Thanks @Cleroth and @Vertexwahn.
-
Improved build configuration and tests (#3118, #3120, #3188, #3189, #3198, #3205, #3207, #3210, #3240, #3256, #3264, #3299, #3302, #3312, #3317, #3328, #3333, #3369, #3373, #3395, #3406, #3411). Thanks @dimztimz (Dimitrij Mijoski), @phprus (Vladislav Shchapov), @DavidKorczynski, @ChrisThrasher (Chris Thrasher), @FrancoisCarouge (François Carouge), @kennyweiss (Kenny Weiss), @luzpaz, @codeinred (Alecto Irene Perez), @Mixaill (Mikhail Paulyshka), @joycebrum (Joyce), @kevinhwang (Kevin Hwang), @Vertexwahn.
-
Fixed a regression in handling empty format specifiers after a colon (
{:}
) (#3086). Thanks @oxidase (Michael Krasnyk). -
Worked around a broken implementation of
std::is_constant_evaluated
in some versions of libstdc++ on clang (#3247, #3281). Thanks [@phprus (Vladislav Shc...
9.1.0
-
fmt::formatted_size
now works at compile time (#3026). For example (godbolt):#include <fmt/compile.h> int main() { using namespace fmt::literals; constexpr size_t n = fmt::formatted_size("{}"_cf, 42); fmt::print("{}\n", n); // prints 2 }
-
Fixed handling of invalid UTF-8 (#3038, #3044, #3056). Thanks @phprus (Vladislav Shchapov) and @skeeto (Christopher Wellons).
-
Improved Unicode support in
ostream
overloads ofprint
(#2994, #3001, #3025). Thanks @dimztimz (Dimitrij Mijoski). -
Fixed handling of the sign specifier in localized formatting on systems with 32-bit
wchar_t
(#3041). -
Added support for wide streams to
fmt::streamed
(#2994). Thanks @phprus (Vladislav Shchapov). -
Added the
n
specifier that disables the output of delimiters when formatting ranges (#2981, #2983). For example (godbolt):#include <fmt/ranges.h> #include <vector> int main() { auto v = std::vector{1, 2, 3}; fmt::print("{:n}\n", v); // prints 1, 2, 3 }
Thanks @BRevzin (Barry Revzin).
-
Worked around problematic
std::string_view
constructors introduced in C++23 (#3030, #3050). Thanks @strega-nil-ms (nicole mazzuca). -
Improve handling (exclusion) of recursive ranges (#2968, #2974). Thanks @Dani-Hub (Daniel Krügler).
-
Improved error reporting in format string compilation (#3055).
-
Improved the implementation of Dragonbox, the algorithm used for the default floating-point formatting (#2984). Thanks @jk-jeon (Junekey Jeon).
-
Fixed issues with floating-point formatting on exotic platforms.
-
Improved the implementation of chrono formatting (#3010). Thanks @phprus (Vladislav Shchapov).
-
Improved documentation (#2966, #3009, #3020, #3037). Thanks @mwinterb, @jcelerier (Jean-Michaël Celerier) and @remiburtin (Rémi Burtin).
-
Improved build configuration (#2991, #2995, #3004, #3007, #3040). Thanks @dimztimz (Dimitrij Mijoski) and @hwhsu1231 (Haowei Hsu).
-
Fixed various warnings and compilation issues (#2969, #2971, #2975, #2982, #2985, #2988, #3000, #3006, #3014, #3015, #3021, #3023, #3024, #3029, #3043, #3052, #3053, #3054). Thanks @h-friederich (Hannes Friederich), @dimztimz (Dimitrij Mijoski), @olupton (Olli Lupton), @bernhardmgruber (Bernhard Manfred Gruber), @phprus (Vladislav Shchapov).
Pull Requests
- Add xchar support for fmt::streamed(). by @phprus in #2961
- Fixed typo in changelog example by @mwinterb in #2966
- Exclude recursive ranges from the formatter specialization for ranges by @Dani-Hub in #2974
- Pointless comparison warnings by @federico-busato in #2971
- The n specifier for ranges. by @brevzin in #2981
- Fix for EDG frontend (Intel, NVHPC compilers) by @phprus in #2982
- Yet another simplification of Dragonbox by @jk-jeon in #2984
- Add additional search paths for doxygen on Windows by @hwhsu1231 in #2991
- Fixes IBM XLC behavior with uint128 fallback by @federico-busato in #2985
- Reduce filesize of the tests on MinGW by @dimztimz in #2995
- Improve Unicode handling when writing to an ostream on Windows by @dimztimz in #2994
- Add fmt:: namespace to doc by @jcelerier in #3009
- Range formatter by @brevzin in #2983
- Fix Unicode handling for ostream under Windows with libc++. by @dimztimz in #3001
- Improve CI on Windows, deprecate AppVeyor by @dimztimz in #3007
- Simplify and improve chrono formatting by @phprus in #3010
- Suppress unused typedef warning by @h-friederich in #3021
- Remove -Wl,--as-needed linker option by @phprus in #3024
- Use is_utf8() in print(std::ostream&, ...) by @dimztimz in #3025
- Constexpr formatted_size by @marksantaniello in #3026
- Fix testsuite on MinGW + MSVCRT by @dimztimz in #3029
- Fix docs by @remiburtin in #3037
- Prepare for deprecating FindPythonInterp module. by @hwhsu1231 in #3040
- nvhpc/22.3: workaround for c++17 mode by @olupton in #3043
- Fix decoder on broken utf8 sequences. by @phprus in #3044
- Disable non-type template args for nvhpc by @bernhardmgruber in #3053
- Disable bogus -Wstringop-overflow on GCC 11 by @phprus in #3054
- Fix bugs in utf8 decoder by @phprus in #3056
New Contributors
- @hwhsu1231 made their first contribution in #2991
- @dimztimz made their first contribution in #2995
- @h-friederich made their first contribution in #3021
- @marksantaniello made their first contribution in #3026
- @remiburtin made their first contribution in #3037
- @bernhardmgruber made their first contribution in #3053
Full Changelog: 9.0.0...9.1.0
9.0.0
-
Switched to the internal floating point formatter for all decimal presentation formats. In particular this results in consistent rounding on all platforms and removing the
s[n]printf
fallback for decimal FP formatting. -
Compile-time floating point formatting no longer requires the header-only mode. For example (godbolt):
#include <array> #include <fmt/compile.h> consteval auto compile_time_dtoa(double value) -> std::array<char, 10> { auto result = std::array<char, 10>(); fmt::format_to(result.data(), FMT_COMPILE("{}"), value); return result; } constexpr auto answer = compile_time_dtoa(0.42);
works with the default settings.
-
Improved the implementation of Dragonbox, the algorithm used for the default floating-point formatting (#2713, #2750). Thanks @jk-jeon (Junekey Jeon).
-
Made
fmt::to_string
work with__float128
. This uses the internal FP formatter and works even on system without__float128
support in[s]printf
. -
Disabled automatic
std::ostream
insertion operator (operator<<
) discovery whenfmt/ostream.h
is included to prevent ODR violations. You can get the old behavior by definingFMT_DEPRECATED_OSTREAM
but this will be removed in the next major release. Usefmt::streamed
orfmt::ostream_formatter
to enable formatting viastd::ostream
instead. -
Added
fmt::ostream_formatter
that can be used to writeformatter
specializations that perform formatting viastd::ostream
. For example (godbolt):#include <fmt/ostream.h> struct date { int year, month, day; friend std::ostream& operator<<(std::ostream& os, const date& d) { return os << d.year << '-' << d.month << '-' << d.day; } }; template <> struct fmt::formatter<date> : ostream_formatter {}; std::string s = fmt::format("The date is {}", date{2012, 12, 9}); // s == "The date is 2012-12-9"
-
Added the
fmt::streamed
function that takes an object and formats it viastd::ostream
. For example (godbolt):#include <thread> #include <fmt/ostream.h> int main() { fmt::print("Current thread id: {}\n", fmt::streamed(std::this_thread::get_id())); }
Note that
fmt/std.h
provides aformatter
specialization forstd::thread::id
so you don't need to format it viastd::ostream
. -
Deprecated implicit conversions of unscoped enums to integers for consistency with scoped enums.
-
Added an argument-dependent lookup based
format_as
extension API to simplify formatting of enums. -
Added experimental
std::variant
formatting support (#2941). For example (godbolt):#include <variant> #include <fmt/std.h> int main() { auto v = std::variant<int, std::string>(42); fmt::print("{}\n", v); }
prints:
variant(42)
Thanks @jehelset.
-
Added experimental
std::filesystem::path
formatting support (#2865, #2902, #2917, #2918). For example (godbolt):#include <filesystem> #include <fmt/std.h> int main() { fmt::print("There is no place like {}.", std::filesystem::path("/home")); }
prints:
There is no place like "/home".
Thanks @phprus (Vladislav Shchapov).
-
Added a
std::thread::id
formatter tofmt/std.h
. For example (godbolt):#include <thread> #include <fmt/std.h> int main() { fmt::print("Current thread id: {}\n", std::this_thread::get_id()); }
-
Added
fmt::styled
that applies a text style to an individual argument (#2793). For example (godbolt):#include <fmt/chrono.h> #include <fmt/color.h> int main() { auto now = std::chrono::system_clock::now(); fmt::print( "[{}] {}: {}\n", fmt::styled(now, fmt::emphasis::bold), fmt::styled("error", fg(fmt::color::red)), "something went wrong"); }
Thanks @rbrugo (Riccardo Brugo).
-
Made
fmt::print
overload for text styles correctly handle UTF-8 (#2681, #2701). Thanks @AlexGuteniev (Alex Guteniev). -
Fixed Unicode handling when writing to an ostream.
-
Added support for nested specifiers to range formatting (#2673). For example (godbolt):
#include <vector> #include <fmt/ranges.h> int main() { fmt::print("{::#x}\n", std::vector{10, 20, 30}); }
prints
[0xa, 0x14, 0x1e]
.Thanks @BRevzin (Barry Revzin).
-
Implemented escaping of wide strings in ranges (#2904). Thanks @phprus (Vladislav Shchapov).
-
Added support for ranges with
begin
/end
found via the argument-dependent lookup (#2807). Thanks @rbrugo (Riccardo Brugo). -
Fixed formatting of certain kinds of ranges of ranges (#2787). Thanks @BRevzin (Barry Revzin).
-
Fixed handling of maps with element types other than
std::pair
(#2944). Thanks @BrukerJWD (Jonathan W). -
Made tuple formatter enabled only if elements are formattable (#2939, #2940). Thanks @jehelset.
-
Made
fmt::join
compatible with format string compilation (#2719, #2720). Thanks @phprus (Vladislav Shchapov). -
Made compile-time checks work with named arguments of custom types and
std::ostream
print
overloads (#2816, #2817, #2819). Thanks @timsong-cpp. -
Removed
make_args_checked
because it is no longer needed for compile-time checks (#2760). Thanks @phprus (Vladislav Shchapov). -
Removed the following deprecated APIs:
_format
,arg_join
, theformat_to
overload that takes a memory buffer,[v]fprintf
that takes anostream
. -
Removed the deprecated implicit conversion of
[const] signed char*
and[const] unsigned char*
to C strings. -
Removed the deprecated
fmt/locale.h
. -
Replaced the deprecated
fileno()
withdescriptor()
inbuffered_file
. -
Moved
to_string_view
to thedetail
namespace since it's an implementation detail. -
Made access mode of a created file consistent with
fopen
by settingS_IWGRP
andS_IWOTH
(#2733). Thanks @arogge (Andreas Rogge). -
Removed a redundant buffer resize when formatting to
std::ostream
(#2842, #2843). Thanks @jcelerier (Jean-Michaël Celerier). -
Made precision computation for strings consistent with width (#2888).
-
Fixed handling of locale separators in floating point formatting (#2830).
-
Made sign specifiers work with
__int128_t
(#2773). -
Improved support for systems such as CHERI with extra data stored in pointers (#2932). Thanks @davidchisnall (David Chisnall).
-
Improved documentation (#2706, #2712, #2789, #2803, #2805, #2815, #2924). Thanks @BRevzin (Barry Revzin), @Pokechu22, @setoye (Alta), @rtobar, @rbrugo (Riccardo Brugo), @anoonD (cre), @leha-bot (Alex).
-
Improved build configuration (#2766, #2772, #2836, #2852, #2907, #2913, #2914). Thanks @kambala-decapitator (Andrey Filipenkov), @mattiasljungstrom (Mattias Ljungström), @kieselnb (Nick Kiesel), @nathannaveen, @Vertexwahn.
-
Fixed various warnings and compilation issues (#2408, #2507, #2697, #2715, #2717, #2722, #2724, #2725, #2726, #2728, #2732, #2738, #2742, #2744, #2745, #2746, #2754, #2755, #2757, #2758, #2761, #2762, #2763, #2765, #2769, #2770, #2771, #2777, #2779, #2782, #2783, #2794, #2796, #2797, #2801, #2802, #2808, #2818, #2819, #2829, #2835, #2848, #2860, #2861, #2882, #2886, #2891, #2892, #2895, #2896, #2903, #2906, #2908, #2909, #2920, #2922, #2927, #2929, #2936, #2937, #2938, #2951, #2954, #2957, #2958, #2960). Thanks @matrackif @Tobi823 (Tobias Hellmann), @ivan-volnov (Ivan Volnov), @VasiliPupkin256, @federico-busato (Federico), @barcharcraz (Charlie Barto), @jk-jeon (Junekey Jeon), @HazardyKnusperkeks (Björn Schäpers), @dalboris (Boris Dalstein), @seanm (Sean McBride), @gsjaardema (Greg Sjaardema), @timsong-cpp, [@seanm (Sean Mc...
8.1.1
-
Restored ABI compatibility with version 8.0.x (#2695, #2696). Thanks @saraedum (Julian Rüth).
-
Fixed chrono formatting on big endian systems (#2698, #2699). Thanks @phprus (Vladislav Shchapov) and @xvitaly (Vitaly Zaitsev).
-
Fixed a linkage error with mingw (#2691, #2692). Thanks @rbberger (Richard Berger).
8.1.0
-
Optimized chrono formatting (#2500, #2537, #2541, #2544, #2550, #2551, #2576, #2577, #2586, #2591, #2594, #2602, #2617, #2628, #2633, #2670, #2671).
Processing of some specifiers such as
%z
and%Y
is now up to 10-20 times faster, for example on GCC 11 with libstdc++:---------------------------------------------------------------------------- Benchmark Before After ---------------------------------------------------------------------------- FMTFormatter_z 261 ns 26.3 ns FMTFormatterCompile_z 246 ns 11.6 ns FMTFormatter_Y 263 ns 26.1 ns FMTFormatterCompile_Y 244 ns 10.5 ns ----------------------------------------------------------------------------
Thanks @phprus (Vladislav Shchapov) and @toughengineer (Pavel Novikov).
-
Implemented subsecond formatting for chrono durations (#2623). For example (godbolt):
#include <fmt/chrono.h> int main() { fmt::print("{:%S}", std::chrono::milliseconds(1234)); }
prints "01.234".
Thanks @matrackif.
-
Fixed handling of precision 0 when formatting chrono durations (#2587, #2588). Thanks @lukester1975.
-
Fixed an overflow on invalid inputs in the
tm
formatter (#2564). Thanks @phprus (Vladislav Shchapov). -
Added
fmt::group_digits
that formats integers with a non-localized digit separator (comma) for groups of three digits. For example (godbolt):#include <fmt/format.h> int main() { fmt::print("{} dollars", fmt::group_digits(1000000)); }
prints "1,000,000 dollars".
-
Added support for faint, conceal, reverse and blink text styles (#2394):
blink.mp4
Thanks @benit8 (Benoît Lormeau) and @data-man (Dmitry Atamanov).
-
Added experimental support for compile-time floating point formatting (#2426, #2470). It is currently limited to the header-only mode. Thanks @alexezeder (Alexey Ochapov).
-
Added UDL-based named argument support to compile-time format string checks (#2640, #2649). For example (godbolt):
#include <fmt/format.h> int main() { using namespace fmt::literals; fmt::print("{answer:s}", "answer"_a=42); }
gives a compile-time error on compilers with C++20
consteval
and non-type template parameter support (gcc 10+) becauses
is not a valid format specifier for an integer.Thanks @alexezeder (Alexey Ochapov).
-
Implemented escaping of string range elements. For example (godbolt):
#include <fmt/ranges.h> #include <vector> int main() { fmt::print("{}", std::vector<std::string>{"\naan"}); }
is now printed as:
["\naan"]
instead of:
[" aan"]
-
Switched to JSON-like representation of maps and sets for consistency with Python's
str.format
. For example (godbolt):#include <fmt/ranges.h> #include <map> int main() { fmt::print("{}", std::map<std::string, int>{{"answer", 42}}); }
is now printed as:
{"answer": 42}
-
Extended
fmt::join
to support C++20-only ranges (#2549). Thanks @BRevzin (Barry Revzin). -
Optimized handling of non-const-iterable ranges and implemented initial support for non-const-formattable types.
-
Disabled implicit conversions of scoped enums to integers that was accidentally introduced in earlier versions (#1841).
-
Deprecated implicit conversion of
[const] signed char*
and[const] unsigned char*
to C strings. -
Deprecated
_format
, a legacy UDL-based format API (#2646). Thanks @alexezeder (Alexey Ochapov). -
Marked
format
,formatted_size
andto_string
as[[nodiscard]]
(#2612). @0x8000-0000 (Florin Iucha). -
Added missing diagnostic when trying to format function and member pointers as well as objects convertible to pointers which is explicitly disallowed (#2598, #2609, #2610). Thanks @AlexGuteniev (Alex Guteniev).
-
Optimized writing to a contiguous buffer with
format_to_n
(#2489). Thanks @Roman-Koshelev. -
Optimized writing to non-
char
buffers (#2477). Thanks @Roman-Koshelev. -
Decimal point is now localized when using the
L
specifier. -
Improved floating point formatter implementation (#2498, #2499). Thanks @Roman-Koshelev.
-
Fixed handling of very large precision in fixed format (#2616).
-
Made a table of cached powers used in FP formatting static (#2509). Thanks @jk-jeon (Junekey Jeon).
-
Resolved a lookup ambiguity with C++20 format-related functions due to ADL (#2639, #2641). Thanks @mkurdej (Marek Kurdej).
-
Removed unnecessary inline namespace qualification (#2642, #2643). Thanks @mkurdej (Marek Kurdej).
-
Implemented argument forwarding in
format_to_n
(#2462, #2463). Thanks @owent (WenTao Ou). -
Fixed handling of implicit conversions in
fmt::to_string
and format string compilation (#2565). -
Changed the default access mode of files created by
fmt::output_file
to-rw-r--r--
for consistency withfopen
(#2530). -
Make
fmt::ostream::flush
public (#2435). -
Improved C++14/17 attribute detection (#2615). Thanks @AlexGuteniev (Alex Guteniev).
-
Improved
consteval
detection for MSVC (#2559). Thanks @DanielaE (Daniela Engert). -
Improved documentation (#2406, #2446, #2493, #2513, #2515, #2522, #2562, #2575, #2606, #2620, #2676). Thanks @sobolevn (Nikita Sobolev), @UnePierre (Max FERGER), @zhsj, @phprus (Vladislav Shchapov), @ericcurtin (Eric Curtin), @Lounarok.
-
Improved fuzzers and added a fuzzer for chrono timepoint formatting (#2461, #2469). @pauldreik (Paul Dreik),
-
Added the
FMT_SYSTEM_HEADERS
CMake option setting which marks {fmt}'s headers as system. It can be used to suppress warnings (#2644, #2651). Thanks @alexezeder (Alexey Ochapov). -
Added the Bazel build system support (#2505, #2516). Thanks @Vertexwahn.
-
Improved build configuration and tests (#2437, #2558, #2648, #2650, #2663, #2677). Thanks @DanielaE (Daniela Engert), @alexezeder (Alexey Ochapov), @phprus (Vladislav Shchapov).
-
Fixed various warnings and compilation issues (#2353, #2356, #2399, #2408, #2414, #2427, #2432, #2442, #2434, #2439, #2447, #2450, #2455, #2465, #2472, #2474, #2476, #2478, #2479, #2481, #2482, #2483, #2490, #2491, #2510, #2518, #2528, #2529, #2539, #2540, #2545, #2555, #2557, #2570, #2573, #2582, #2605, #2611, #2647, #2627, #2630, #2635, #2638, #2653, #2654, #2661, #2664, #2684). Thanks @DanielaE (Daniela Engert), @mwinterb, @cdacamar (Cameron DaCamara), @TrebledJ (Johnathan), @bodomartin (brm), @cquammen (Cory Quammen), @white238 (Chris White), @mmarkeloff (Max), @palacaze (Pierre-Antoine Lacaze), @jcelerier (Jean-Michaël Celerier), @mborn-adi (Mathias Born), @BrukerJWD (Jonathan W), @spyridon97 (Spiros Tsalikis), @phprus (Vladislav Shchapov), @oliverlee (Oliver Lee), @joshessman-llnl (Josh Essman), @akohlmey (Axel Kohlmeyer), @timkalu, @olupton (Olli Lupton), @Acretock, @alexezeder (Alexey Ochapov), @andrewcorrigan (Andrew Corrigan), @lucpelletier, @HazardyKnusperkeks (Björn Schäpers).
8.0.1
-
Fixed the version number in the inline namespace (#2374).
-
Added a missing presentation type check for
std::string
(#2402). -
Fixed a linkage error when mixing code built with clang and gcc (#2377).
-
Fixed documentation issues (#2396, #2403, #2406). Thanks @mkurdej (Marek Kurdej).
-
Removed dead code in FP formatter ( #2398). Thanks @javierhonduco (Javier Honduvilla Coto).
-
Fixed various warnings and compilation issues (#2351, #2359, #2365, #2368, #2370, #2376, #2381, #2382, #2386, #2389, #2395, #2397, #2400 #2401, #2407). Thanks @zx2c4 (Jason A. Donenfeld), @AidanSun05 (Aidan Sun), @mattiasljungstrom (Mattias Ljungström), @joemmett (Jonathan Emmett), @erengy (Eren Okka), @patlkli (Patrick Geltinger), @gsjaardema (Greg Sjaardema), @phprus (Vladislav Shchapov).
8.0.0
-
Enabled compile-time format string check by default. For example (godbolt):
#include <fmt/core.h> int main() { fmt::print("{:d}", "I am not a number"); }
gives a compile-time error on compilers with C++20
consteval
support (gcc 10+, clang 11+) becaused
is not a valid format specifier for a string.To pass a runtime string wrap it in
fmt::runtime
:fmt::print(fmt::runtime("{:d}"), "I am not a number");
-
Added compile-time formatting (#2019, #2044, #2056, #2072, #2075, #2078, #2129, #2326). For example (godbolt):
#include <fmt/compile.h> consteval auto compile_time_itoa(int value) -> std::array<char, 10> { auto result = std::array<char, 10>(); fmt::format_to(result.data(), FMT_COMPILE("{}"), value); return result; } constexpr auto answer = compile_time_itoa(42);
Most of the formatting functionality is available at compile time with a notable exception of floating-point numbers and pointers. Thanks @alexezeder (Alexey Ochapov).
-
Optimized handling of format specifiers during format string compilation. For example, hexadecimal formatting (
"{:x}"
) is now 3-7x faster than before when usingformat_to
with format string compilation and a stack-allocated buffer (#1944).Before (7.1.3):
---------------------------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------------------------- FMTCompileOld/0 15.5 ns 15.5 ns 43302898 FMTCompileOld/42 16.6 ns 16.6 ns 43278267 FMTCompileOld/273123 18.7 ns 18.6 ns 37035861 FMTCompileOld/9223372036854775807 19.4 ns 19.4 ns 35243000 ----------------------------------------------------------------------------
After (8.x):
---------------------------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------------------------- FMTCompileNew/0 1.99 ns 1.99 ns 360523686 FMTCompileNew/42 2.33 ns 2.33 ns 279865664 FMTCompileNew/273123 3.72 ns 3.71 ns 190230315 FMTCompileNew/9223372036854775807 5.28 ns 5.26 ns 130711631 ----------------------------------------------------------------------------
It is even faster than
std::to_chars
from libc++ compiled with clang on macOS:---------------------------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------------------------- ToChars/0 4.42 ns 4.41 ns 160196630 ToChars/42 5.00 ns 4.98 ns 140735201 ToChars/273123 7.26 ns 7.24 ns 95784130 ToChars/9223372036854775807 8.77 ns 8.75 ns 75872534 ----------------------------------------------------------------------------
In other cases, especially involving
std::string
construction, the speed up is usually lower because handling format specifiers takes a smaller fraction of the total time. -
Added the
_cf
user-defined literal to represent a compiled format string. It can be used instead of theFMT_COMPILE
macro (#2043, #2242):#include <fmt/compile.h> using namespace fmt::literals; auto s = fmt::format(FMT_COMPILE("{}"), 42); // 🙁 not modern auto s = fmt::format("{}"_cf, 42); // 🙂 modern as hell
It requires compiler support for class types in non-type template parameters (a C++20 feature) which is available in GCC 9.3+. Thanks @alexezeder (Alexey Ochapov).
-
Format string compilation now requires
format
functions offormatter
specializations for user-defined types to beconst
:template <> struct fmt::formatter<my_type>: formatter<string_view> { template <typename FormatContext> auto format(my_type obj, FormatContext& ctx) const { // Note const here. // ... } };
-
Added UDL-based named argument support to format string compilation (#2243, #2281). For example:
#include <fmt/compile.h> using namespace fmt::literals; auto s = fmt::format(FMT_COMPILE("{answer}"), "answer"_a = 42);
Here the argument named "answer" is resolved at compile time with no runtime overhead. Thanks @alexezeder (Alexey Ochapov).
-
Added format string compilation support to
fmt::print
(#2280, #2304). Thanks @alexezeder (Alexey Ochapov). -
Added initial support for compiling {fmt} as a C++20 module (#2235, #2240, #2260, #2282, #2283, #2288, #2298, #2306, #2307, #2309, #2318, #2324, #2332, #2340). Thanks @DanielaE (Daniela Engert).
-
Made symbols private by default reducing shared library size (#2301). For example there was a ~15% reported reduction on one platform. Thanks @sergiud (Sergiu Deitsch).
-
Optimized includes making the result of preprocessing
fmt/format.h
~20% smaller with libstdc++/C++20 and slightly improving build times (#1998). -
Added support of ranges with non-const
begin
/end
(#1953). Thanks @kitegi (sarah). -
Added support of
std::byte
and other formattable types tofmt::join
(#1981, #2040, #2050, #2262). For example:#include <fmt/format.h> #include <cstddef> #include <vector> int main() { auto bytes = std::vector{std::byte(4), std::byte(2)}; fmt::print("{}", fmt::join(bytes, "")); }
prints "42".
Thanks @kamibo (Camille Bordignon).
-
Implemented the default format for
std::chrono::system_clock
(#2319, #2345). For example:#include <fmt/chrono.h> int main() { fmt::print("{}", std::chrono::system_clock::now()); }
prints "2021-06-18 15:22:00" (the output depends on the current date and time). Thanks @sunmy2019.
-
Made more chrono specifiers locale independent by default. Use the
'L'
specifier to get localized formatting. For example:#include <fmt/chrono.h> int main() { std::locale::global(std::locale("ru_RU.UTF-8")); auto monday = std::chrono::weekday(1); fmt::print("{}\n", monday); // prints "Mon" fmt::print("{:L}\n", monday); // prints "пн" }
-
Improved locale handling in chrono formatting (#2337, #2349, #2350). Thanks @phprus (Vladislav Shchapov).
-
Deprecated
fmt/locale.h
moving the formatting functions that take a locale tofmt/format.h
(char
) andfmt/xchar
(other overloads). This doesn't introduce a dependency on<locale>
so there is virtually no compile time effect. -
Made parameter order in
vformat_to
consistent withformat_to
(#2327). -
Added support for time points with arbitrary durations (#2208). For example:
#include <fmt/chrono.h> int main() { using tp = std::chrono::time_point< std::chrono::system_clock, std::chrono::seconds>; fmt::print("{:%S}", tp(std::chrono::seconds(42))); }
prints "42".
-
Formatting floating-point numbers no longer produces trailing zeros by default for consistency with
std::format
. For example:#include <fmt/core.h> int main() { fmt::print("{0:.3}", 1.1); }
prints "1.1". Use the
'#'
specifier to keep trailing zeros. -
Dropped a limit on the number of elements in a range and replaced
{}
with[]
as range delimiters for consistency with Python'sstr.format
. -
The
'L'
specifier for locale-specific numeric formatting can now be combined with presentation specifiers as instd::format
. For example:#include <fmt/core.h> #include <locale> int main() { std::locale::global(std::locale("fr_FR.UTF-8")); fmt::print("{0:.2Lf}", 0.42); }
prints "0,42". The deprecated
'n'
specifier has been removed. -
Made the
0
specifier ignored for infinity and NaN (#2305, #2310). Thanks @Liedtke (Matthias Liedtke). -
Made the hexfloat formatting use the right alignment by default (#2308, #2317). Thanks @Liedtke (Matthias Liedtke).
-
Removed the deprecated numeric alignment (
'='
). Use the'0'
specifier instead. -
Removed the deprecated
fmt/posix.h
header that has been replaced withfmt/os.h
. -
Removed the deprecated
format_to_n_context
,format_to_n_args
andmake_format_to_n_args
. They have been replaced withformat_context
,format_args
andmake_format_args
respectively. -
Moved
wchar_t
-specific functions and types tofmt/xchar.h
. You can defineFMT_DEPRECATED_INCLUDE_XCHAR
to automatically includefmt/xchar.h
fromfmt/format.h
but this will be disabled in the next major release. -
Fixed handling of the
'+'
spec...
7.1.3
7.1.2
7.1.1
-
Fixed ABI compatibility with 7.0.x (#1961).
-
Added the
FMT_ARM_ABI_COMPATIBILITY
macro to work around ABI incompatibility between GCC and Clang on ARM (#1919). -
Worked around a SFINAE bug in GCC 8 (#1957).
-
Fixed linkage errors when building with GCC's LTO (#1955).
-
Fixed a compilation error when building without
__builtin_clz
or equivalent (#1968). Thanks @tohammer (Tobias Hammer). -
Fixed a sign conversion warning (#1964). Thanks @OptoCloud.