-
Improved debug codegen.
-
Added an experimental
fmt::writer
API that can be used for writing to different destinations such as files or strings (#2354). For example (godbolt):#include <fmt/os.h> void write_text(fmt::writer w) { w.print("The answer is {}.", 42); } int main() { // Write to FILE. write_text(stdout); // Write to fmt::ostream. auto f = fmt::output_file("myfile"); write_text(f); // Write to std::string. auto sb = fmt::string_buffer(); write_text(sb); std::string s = sb.str(); }
-
Improved C++20 module support (#4081, #4083, #4084, #4152, #4169, #4239). Thanks @kamrann, @Arghnews.
-
Made
std::expected<void, E>
formattable (#4145, #4148). For example (godbolt):fmt::print("{}", std::expected<void, int>());
prints
expected()
Thanks @phprus.
-
Added support for
_BitInt
formatting when using clang (#4007, #4072, #4140, #4176). For example (godbolt):using int42 = _BitInt(42); fmt::print("{}", int42(100));
Thanks @Arghnews.
-
Added the
n
specifier for tuples and pairs (#4107). Thanks @someonewithpc. -
Added support for tuple-like types to
fmt::join
(#4226, #4230). Thanks @phprus. -
Made more types formattable at compile time (#4127). Thanks @AnthonyVH.
-
Implemented a more efficient compile-time
fmt::formatted_size
(#4102, #4103). Thanks @phprus. -
Added a formatter for
std::reference_wrapper
(#4163, #4164). Thanks @yfeldblum and @phprus. -
Added experimental padding support (glibc
strftime
extension) to%m
,%j
and%Y
. (#4161). Thanks @KKhanhH. -
Made microseconds formatted as
us
instead ofµs
if the Unicode support is disabled (#4088. -
Fixed an unreleased regression in transcoding of surrogate pairs (#4094, #4095). Thanks @phprus.
-
Made
fmt::appender
satisfystd::output_iterator
concept (#4092, #4093). Thanks @phprus. -
Made
std::iterator_traits<fmt::appender>
standard-conforming (#4185). Thanks @CaseyCarter. -
Made it easier to reuse
formatter<std::string_view>
for types with implicit conversion tostd::string_view
(#4036, #4055). Thanks @Arghnews. -
Fixed compile-time formatting of some string types (#4065). Thanks @torshepherd.
-
Made it possible to disable
<filesystem>
use viaFMT_CPP_LIB_FILESYSTEM
for compatibility with some video game console SDKs, e.g. Nintendo Switch SDK (#4257, #4258, #4259). Thanks @W4RH4WK and @phprus. -
Fixed compatibility with platforms that use 80-bit
long double
(#4245, #4246). Thanks @jsirpoma. -
Made compiled version of
fmt::format_to
work withstd::back_insert_iterator<std::vector<char>>
(#4206, #4211). Thanks @phprus. -
Made
fmt::to_string
takefmt::basic_memory_buffer
by const reference (#4261, #4262). Thanks @sascha-devel. -
Added
fmt::dynamic_format_arg_store::size
(#4270). Thanks @hannes-harnisch. -
Improved include directory ordering to reduce the chance of including incorrect headers when using multiple versions of {fmt} (#4116). Thanks @cdzhan.
-
Improved documentation and README (#4066, #4117, #4235). Thanks @zyctree, @nikola-sh.
-
Improved the documentation generator (#4110, #4115). Thanks @rturrado.
-
Improved {fmt}'s compatibility with Nintendo Switch console SDK (#4258, #4259). Thanks @W4RH4WK, @phprus.
-
Fixed various warnings and compilation issues (#2708, #4109, #4113, #4125, #4129, #4130, #4131, #4132, #4144, #4159, #4170, #4177, #4187, #4188, #4194, #4200, #4208, #4210, #4220, #4231, #4232, #4233, #4236, #4267, #4271). Thanks @torsten48, @Arghnews, @tinfoilboy, @aminya, @Ottani, @zeroomega, @c4v4, @kongy, @vinayyadav3016, @sergio-nsk, @phprus, @Arghnews, @YexuanXiao.
-
Fixed performance regressions when using
std::back_insert_iterator
withfmt::format_to
(#4070). -
Fixed handling of
std::generator
and move-only iterators (#4053, #4057). Thanks @Arghnews. -
Made
formatter<std::string_view>::parse
work with types convertible tostd::string_view
(#4036, #4055). Thanks @Arghnews. -
Made
volatile void*
formattable (#4049, #4056). Thanks @Arghnews. -
Made
Glib::ustring
not be confused withstd::string
(#4052). -
Made
fmt::context
iterator compatible with STL algorithms that rely on iterator category (#4079).
-
Fixed version number in the inline namespace (#4047).
-
Fixed disabling Unicode support via CMake (#4051).
-
Fixed deprecated
visit_format_arg
(#4043). Thanks @nebkat. -
Fixed handling of a sign and improved the
std::complex
formater (#4034, #4050). Thanks @tesch1 and @phprus. -
Fixed ADL issues in
fmt::printf
when using C++20 (#4042). Thanks @toge. -
Removed a redundant check in the formatter for
std::expected
(#4040). Thanks @phprus.
-
Added
fmt/base.h
which provides a subset of the API with minimal include dependencies and enough functionality to replace all uses of theprintf
family of functions. This brings the compile time of code using {fmt} much closer to the equivalentprintf
code as shown on the following benchmark that compiles 100 source files:Method Compile Time (s) printf 1.6 IOStreams 25.9 fmt 10.x 19.0 fmt 11.0 4.8 tinyformat 29.1 Boost Format 55.0 This gives almost 4x improvement in build speed compared to version 10. Note that the benchmark is purely formatting code and includes. In real projects the difference from
printf
will be smaller partly because common standard headers will be included in almost any translation unit (TU) anyway. In particular, in every case exceptprintf
above ~1s is spent in total on including<type_traits>
in all TUs. -
Optimized includes in other headers such as
fmt/format.h
which is now roughly equivalent to the oldfmt/core.h
in terms of build speed. -
Migrated the documentation at https://fmt.dev/ from Sphinx to MkDocs.
-
Improved C++20 module support (#3990, #3991, #3993, #3994, #3997, #3998, #4004, #4005, #4006, #4013, #4027, #4029). In particular, native CMake support for modules is now used if available. Thanks @yujincheng08 and @matt77hias.
-
Added an option to replace standard includes with
import std
enabled via theFMT_IMPORT_STD
macro (#3921, #3928). Thanks @matt77hias. -
Exported
fmt::range_format
,fmt::range_format_kind
andfmt::compiled_string
from thefmt
module (#3970, #3999). Thanks @matt77hias and @yujincheng08. -
Improved integration with stdio in
fmt::print
, enabling direct writes into a C stream buffer in common cases. This may give significant performance improvements ranging from tens of percent to 2x and eliminates dynamic memory allocations on the buffer level. It is currently enabled for built-in and string types with wider availability coming up in future releases.For example, it gives ~24% improvement on a simple benchmark compiled with Apple clang version 15.0.0 (clang-1500.1.0.2.5) and run on macOS 14.2.1:
------------------------------------------------------- Benchmark Time CPU Iterations ------------------------------------------------------- printf 81.8 ns 81.5 ns 8496899 fmt::print (10.x) 63.8 ns 61.9 ns 11524151 fmt::print (11.0) 51.3 ns 51.0 ns 13846580
-
Improved safety of
fmt::format_to
when writing to an array (#3805). For example (godbolt):auto volkswagen = char[4]; auto result = fmt::format_to(volkswagen, "elephant");
no longer results in a buffer overflow. Instead the output will be truncated and you can get the end iterator and whether truncation occurred from the
result
object. Thanks @ThePhD. -
Enabled Unicode support by default in MSVC, bringing it on par with other compilers and making it unnecessary for users to enable it explicitly. Most of {fmt} is encoding-agnostic but this prevents mojibake in places where encoding matters such as path formatting and terminal output. You can control the Unicode support via the CMake
FMT_UNICODE
option. Note that some {fmt} packages such as the one in vcpkg have already been compiled with Unicode enabled. -
Added a formatter for
std::expected
(#3834). Thanks @dominicpoeschko. -
Added a formatter for
std::complex
(#1467, #3886, #3892, #3900). Thanks @phprus. -
Added a formatter for
std::type_info
(#3978). Thanks @matt77hias. -
Specialized
formatter
forstd::basic_string
types with custom traits and allocators (#3938, #3943). Thanks @dieram3. -
Added formatters for
std::chrono::day
,std::chrono::month
,std::chrono::year
andstd::chrono::year_month_day
(#3758, #3772, #3906, #3913). For example:#include <fmt/chrono.h> #include <fmt/color.h> int main() { fmt::print(fg(fmt::color::green), "{}\n", std::chrono::day(7)); }
prints a green day:
Thanks @zivshek.
-
Fixed handling of precision in
%S
(#3794, #3814). Thanks @js324. -
Added support for the
-
specifier (glibcstrftime
extension) to day of the month (%d
) and week of the year (%W
,%U
,%V
) specifiers (#3976). Thanks @ZaheenJ. -
Fixed the scope of the
-
extension in chrono formatting so that it doesn't apply to subsequent specifiers (#3811, #3812). Thanks @phprus. -
Improved handling of
time_point::min()
(#3282). -
Added support for character range formatting (#3857, #3863). Thanks @js324.
-
Added
string
anddebug_string
range formatters (#3973, #4024). Thanks @matt77hias. -
Enabled ADL for
begin
andend
infmt::join
(#3813, #3824). Thanks @bbolli. -
Made contiguous iterator optimizations apply to
std::basic_string
iterators (#3798). Thanks @phprus. -
Added support for ranges with mutable
begin
andend
(#3752, #3800, #3955). Thanks @tcbrindle and @Arghnews. -
Added support for move-only iterators to
fmt::join
(#3802, #3946). Thanks @Arghnews. -
Moved range and iterator overloads of
fmt::join
tofmt/ranges.h
, next to other overloads. -
Fixed handling of types with
begin
returningvoid
such as Eigen matrices (#3839, #3964). Thanks @Arghnews. -
Added an
fmt::formattable
concept (#3974). Thanks @matt77hias. -
Added support for
__float128
(#3494). -
Fixed rounding issues when formatting
long double
with fixed precision (#3539). -
Made
fmt::isnan
not trigger floating-point exception for NaN values (#3948, #3951). Thanks @alexdewar. -
Removed dependency on
<memory>
forstd::allocator_traits
when possible (#3804). Thanks @phprus. -
Enabled compile-time checks in formatting functions that take text colors and styles.
-
Deprecated wide stream overloads of
fmt::print
that take text styles. -
Made format string compilation work with clang 12 and later despite only partial non-type template parameter support (#4000, #4001). Thanks @yujincheng08.
-
Made
fmt::iterator_buffer
's move constructornoexcept
(#3808). Thanks @waywardmonkeys. -
Started enforcing that
formatter::format
is const for compatibility withstd::format
(#3447). -
Added
fmt::basic_format_arg::visit
and deprecatedfmt::visit_format_arg
. -
Made
fmt::basic_string_view
not constructible fromnullptr
for consistency withstd::string_view
in C++23 (#3846). Thanks @dalle. -
Fixed
fmt::group_digits
for negative integers (#3891, #3901). Thanks @phprus. -
Fixed handling of negative ids in
fmt::basic_format_args::get
(#3945). Thanks @marlenecota. -
Improved named argument validation (#3817).
-
Disabled copy construction/assignment for
fmt::format_arg_store
and fixed moved construction (#3833). Thanks @ivafanas. -
Worked around a locale issue in RHEL/devtoolset (#3858, #3859). Thanks @g199209.
-
Added RTTI detection for MSVC (#3821, #3963). Thanks @edo9300.
-
Migrated the documentation from Sphinx to MkDocs.
-
Improved documentation and README (#3775, #3784, #3788, #3789, #3793, #3818, #3820, #3822, #3843, #3890, #3894, #3895, #3905, #3942, #4008). Thanks @zencatalyst, WolleTD, @tupaschoal, @Dobiasd, @frank-weinberg, @bbolli, @phprus, @waywardmonkeys, @js324 and @tchaikov.
-
Improved CI and tests (#3878, #3883, #3897, #3979, #3980, #3988, #4010, #4012, #4038). Thanks @vgorrX, @waywardmonkeys, @tchaikov and @phprus.
-
Fixed buffer overflow when using format string compilation with debug format and
std::back_insert_iterator
(#3795, #3797). Thanks @phprus. -
Improved Bazel support (#3792, #3801, #3962, #3965). Thanks @Vertexwahn.
-
Improved/fixed the CMake config (#3777, #3783, #3847, #3907). Thanks @phprus and @xTachyon.
-
Fixed various warnings and compilation issues (#3685, #3769, #3796, #3803, #3806, #3807, #3809, #3810, #3830, #3832, #3835, #3844, #3854, #3856, #3865, #3866, #3880, #3881, #3884, #3898, #3899, #3909, #3917, #3923, #3924, #3925, #3930, #3931, #3933, #3935, #3937, #3967, #3968, #3972, #3983, #3992, #3995, #4009, #4023). Thanks @hmbj, @phprus, @res2k, @Baardi, @matt77hias, @waywardmonkeys, @hmbj, @yakra, @prlw1, @Arghnews, @mtillmann0, @ShifftC, @eepp, @jimmy-park and @ChristianGebhardt.
-
Added support for the
%j
specifier (the number of days) forstd::chrono::duration
(#3643, #3732). Thanks @intelfx. -
Added support for the chrono suffix for days and changed the suffix for minutes from "m" to the correct "min" (#3662, #3664). For example (godbolt):
#include <fmt/chrono.h> int main() { fmt::print("{}\n", std::chrono::days(42)); // prints "42d" }
Thanks @Richardk2n.
-
Fixed an overflow in
std::chrono::time_point
formatting with large dates (#3725, #3727). Thanks @cschreib. -
Added a formatter for
std::source_location
(#3730). For example (godbolt):#include <source_location> #include <fmt/std.h> int main() { fmt::print("{}\n", std::source_location::current()); }
prints
/app/example.cpp:5:51: int main()
Thanks @felix642.
-
Added a formatter for
std::bitset
(#3660). For example (godbolt):#include <bitset> #include <fmt/std.h> int main() { fmt::print("{}\n", std::bitset<6>(42)); // prints "101010" }
Thanks @muggenhor.
-
Added an experimental
nested_formatter
that provides an easy way of applying a formatter to one or more subobjects while automatically handling width, fill and alignment. For example:#include <fmt/format.h> struct point { double x, y; }; template <> struct fmt::formatter<point> : nested_formatter<double> { auto format(point p, format_context& ctx) const { return write_padded(ctx, [=](auto out) { return format_to(out, "({}, {})", nested(p.x), nested(p.y)); }); } }; int main() { fmt::print("[{:>20.2f}]", point{1, 2}); }
prints
[ (1.00, 2.00)]
-
Added the generic representation (
g
) tostd::filesystem::path
(#3715, #3729). For example:#include <filesystem> #include <fmt/std.h> int main() { fmt::print("{:g}\n", std::filesystem::path("C:\\foo")); }
prints
"C:/foo"
on Windows.Thanks @js324.
-
Made
format_as
work with references (#3739). Thanks @tchaikov. -
Fixed formatting of invalid UTF-8 with precision (#3284).
-
Fixed an inconsistency between
fmt::to_string
andfmt::format
(#3684). -
Disallowed unsafe uses of
fmt::styled
(#3625):auto s = fmt::styled(std::string("dangle"), fmt::emphasis::bold); fmt::print("{}\n", s); // compile error
Pass
fmt::styled(...)
as a parameter instead. -
Added a null check when formatting a C string with the
s
specifier (#3706). -
Disallowed the
c
specifier forbool
(#3726, #3734). Thanks @js324. -
Made the default formatting unlocalized in
fmt::ostream_formatter
for consistency with the rest of the library (#3460). -
Fixed localized formatting in bases other than decimal (#3693, #3750). Thanks @js324.
-
Fixed a performance regression in experimental
fmt::ostream::print
(#3674). -
Added synchronization with the underlying output stream when writing to the Windows console (#3668, #3688, #3689). Thanks @Roman-Koshelev and @dimztimz.
-
Changed to only export
format_error
when {fmt} is built as a shared library (#3626, #3627). Thanks @phprus. -
Made
fmt::streamed
constexpr
. (#3650). Thanks @muggenhor. -
Made
fmt::format_int
constexpr
(#4031, #4032). Thanks @dixlorenz. -
Enabled
consteval
on older versions of MSVC (#3757). Thanks @phprus. -
Added an option to build without
wchar_t
support on Windows (#3631, #3636). Thanks @glebm. -
Improved build and CI configuration (#3679, #3701, #3702, #3749). Thanks @jcar87, @pklima and @tchaikov.
-
Fixed various warnings, compilation and test issues (#3607, #3610, #3624, #3630, #3634, #3638, #3645, #3646, #3647, #3652, #3654, #3663, #3670, #3680, #3694, #3695, #3699, #3705, #3710, #3712, #3713, #3714, #3716, #3723, #3738, #3740, #3741, #3743, #3745, #3747, #3748, #3751, #3754, #3755, #3760, #3762, #3763, #3764, #3774, #3779). Thanks @danakj, @vinayyadav3016, @cyyever, @phprus, @qimiko, @saschasc, @gsjaardema, @lazka, @Zhaojun-Liu, @carlsmedstad, @hotwatermorning, @cptFracassa, @kuguma, @PeterJohnson, @H1X4Dev, @asantoni, @eltociear, @msimberg, @tchaikov, @waywardmonkeys.
-
Improved documentation and README (#2086, #3637, #3642, #3653, #3655, #3661, #3673, #3677, #3737, #3742, #3744). Thanks @idzm, @perlun, @joycebrum, @fennewald, @reinhardt1053, @GeorgeLS.
-
Updated CI dependencies (#3615, #3622, #3623, #3666, #3696, #3697, #3759, #3782).
- Added formatters for
std::atomic
andatomic_flag
(#3574, #3594). Thanks @wangzw and @AlexGuteniev. - Fixed an error about partial specialization of
formatter<string>
after instantiation when compiled with gcc and C++20 (#3584). - Fixed compilation as a C++20 module with gcc and clang (#3587, #3597, #3605). Thanks @MathewBensonCode.
- Made
fmt::to_string
work with types that haveformat_as
overloads (#3575). Thanks @phprus. - Made
formatted_size
work with integral format specifiers at compile time (#3591). Thanks @elbeno. - Fixed a warning about the
no_unique_address
attribute on clang-cl (#3599). Thanks @lukester1975. - Improved compatibility with the legacy GBK encoding (#3598, #3599). Thanks @YuHuanTin.
- Added OpenSSF Scorecard analysis (#3530, #3571). Thanks @joycebrum.
- Updated CI dependencies (#3591, #3592, #3593, #3602).
-
Optimized format string compilation resulting in up to 40% speed up in compiled
format_to
and ~4x speed up in compiledformat_to_n
on a concatenation benchmark (#3133, #3484).{fmt} 10.0:
--------------------------------------------------------- Benchmark Time CPU Iterations --------------------------------------------------------- BM_format_to 78.9 ns 78.9 ns 8881746 BM_format_to_n 568 ns 568 ns 1232089
{fmt} 10.1:
--------------------------------------------------------- Benchmark Time CPU Iterations --------------------------------------------------------- BM_format_to 54.9 ns 54.9 ns 12727944 BM_format_to_n 133 ns 133 ns 5257795
-
Optimized storage of an empty allocator in
basic_memory_buffer
(#3485). Thanks @Minty-Meeo. -
Added formatters for proxy references to elements of
std::vector<bool>
andstd::bitset<N>
(#3567, #3570). For example (godbolt):#include <vector> #include <fmt/std.h> int main() { auto v = std::vector<bool>{true}; fmt::print("{}", v[0]); }
Thanks @phprus and @felix642.
-
Fixed an ambiguous formatter specialization for containers that look like container adaptors such as
boost::flat_set
(#3556, #3561). Thanks @5chmidti. -
Fixed compilation when formatting durations not convertible from
std::chrono::seconds
(#3430). Thanks @patlkli. -
Made the
formatter
specialization forchar*
const-correct (#3432). Thanks @timsong-cpp. -
Made
{}
and{:}
handled consistently during compile-time checks (#3526). -
Disallowed passing temporaries to
make_format_args
to improve API safety by preventing dangling references. -
Improved the compile-time error for unformattable types (#3478). Thanks @BRevzin.
-
Improved the floating-point formatter (#3448, #3450). Thanks @florimond-collette.
-
Fixed handling of precision for
long double
larger than 64 bits. (#3539, #3564). -
Made floating-point and chrono tests less platform-dependent (#3337, #3433, #3434). Thanks @phprus.
-
Removed the remnants of the Grisu floating-point formatter that has been replaced by Dragonbox in earlier versions.
-
Added
throw_format_error
to the public API (#3551). Thanks @mjerabek. -
Made
FMT_THROW
assert even if assertions are disabled when compiling with exceptions disabled (#3418, #3439). Thanks @BRevzin. -
Made
format_as
andstd::filesystem::path
formatter work with exotic code unit types. (#3457, #3476). Thanks @gix and @hmbj. -
Added support for the
?
format specifier tostd::filesystem::path
and made the default unescaped for consistency with strings. -
Deprecated the wide stream overload of
printf
. -
Removed unused
basic_printf_parse_context
. -
Improved RTTI detection used when formatting exceptions (#3468). Thanks @danakj.
-
Improved compatibility with VxWorks7 (#3467). Thanks @wenshan1.
-
Improved documentation (#3174, #3423, #3454, #3458, #3461, #3487, #3515). Thanks @zencatalyst, @rlalik and @mikecrowe.
-
Improved build and CI configurations (#3449, #3451, #3452, #3453, #3459, #3481, #3486, #3489, #3496, #3517, #3523, #3563). Thanks @joycebrum, @glebm, @phprus, @petrmanek, @setoye and @abouvier.
-
Fixed various warnings and compilation issues (#3408, #3424, #3444, #3446, #3475, #3482, #3492, #3493, #3508, #3509, #3533, #3542, #3543, #3540, #3544, #3548, #3549, #3550, #3552). Thanks @adesitter, @hmbj, @Minty-Meeo, @phprus, @TobiSchluter, @kieranclancy, @alexeedm, @jurihock, @Ozomahtli and @razaqq.
-
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.
-
Replaced
snprintf
-based hex float formatter with an internal implementation (#3179, #3203). This removes the last usage ofs(n)printf
in {fmt}. Thanks @phprus. -
Fixed alignment of floating-point numbers with localization (#3263, #3272). Thanks @ShawnZhong.
-
Made handling of
#
consistent withstd::format
. -
Improved C++20 module support (#3134, #3254, #3386, #3387, #3388, #3392, #3397, #3399, #3400). Thanks @laitingsheng, @Orvid and @DanielaE.
-
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.
-
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 @phprus and @BRevzin.
-
Added precision support to
%S
(#3148). Thanks @SappyJoy -
Added support for
std::utc_time
(#3098, #3110). Thanks @patrickroocks. -
Switched formatting of
std::chrono::system_clock
from local time to UTC for compatibility with the standard (#3199, #3230). Thanks @ned14. -
Added support for
%Ez
and%Oz
to chrono formatters. (#3220, #3222). Thanks @phprus. -
Improved validation of format specifiers for
std::chrono::duration
(#3219, #3232). Thanks @ShawnZhong. -
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.
-
Experimental: implemented glibc extension for padding seconds, minutes and hours (#2959, #3271). Thanks @ShawnZhong.
-
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 and @phprus.
-
Moved
std::error_code
formatter fromfmt/os.h
tofmt/std.h
. (#3125). Thanks @phprus. -
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.
-
Added a formatter for
std::optional
tofmt/std.h
(#1367, #3303). 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. -
Fixed formatting of noncopyable ranges and nested ranges of chars (#3158 #3286, #3290). Thanks @BRevzin.
-
Fixed issues with formatting of paths and ranges of paths (#3319, #3321 #3322). Thanks @phprus.
-
Improved handling of invalid Unicode in paths.
-
Enabled compile-time checks on Apple clang 14 and later (#3331). Thanks @cloyce.
-
Improved compile-time checks of named arguments (#3105, #3214). Thanks @rbrich.
-
Fixed formatting when both alignment and
0
are given (#3236, #3248). Thanks @ShawnZhong. -
Improved Unicode support in the experimental file API on Windows (#3234, #3293). Thanks @Fros1er.
-
Unified UTF transcoding (#3416). Thanks @phprus.
-
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. -
Added
starts_with
to the fallbackstring_view
implementation (#3080). Thanks @phprus. -
Added
fmt::basic_format_string::get()
for compatibility withbasic_format_string
(#3111). Thanks @huangqinjin. -
Added
println
for compatibility with C++23 (#3267). Thanks @ShawnZhong. -
Renamed the
FMT_EXPORT
macro for shared library usage toFMT_LIB_EXPORT
. -
Improved documentation (#3108, #3169, #3243). #3404, #4002). Thanks @Cleroth, @Vertexwahn and @yujincheng08.
-
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, @phprus, @DavidKorczynski, @ChrisThrasher, @FrancoisCarouge, @kennyweiss, @luzpaz, @codeinred, @Mixaill, @joycebrum, @kevinhwang and @Vertexwahn.
-
Fixed a regression in handling empty format specifiers after a colon (
{:}
) (#3086). Thanks @oxidase. -
Worked around a broken implementation of
std::is_constant_evaluated
in some versions of libstdc++ on clang (#3247, #3281). Thanks @phprus. -
Fixed formatting of volatile variables (#3068).
-
Fixed various warnings and compilation issues (#3057, #3066, #3072, #3082, #3091, #3092, #3093, #3095, #3096, #3097, #3128, #3129, #3137, #3139, #3140, #3142, #3149, #3150, #3154, #3163, #3178, #3184, #3196, #3204, #3206, #3208, #3213, #3216, #3224, #3226, #3228, #3229, #3259, #3274, #3287, #3288, #3292, #3295, #3296, #3298, #3325, #3326, #3334, #3342, #3343, #3351, #3352, #3362, #3365, #3366, #3374, #3377, #3378, #3381, #3398, #3413, #3415). Thanks @phprus, @gsjaardema, @NewbieOrange, @EngineLessCC, @asmaloney, @HazardyKnusperkeks, @sergiud, @Youw, @thesmurph, @czudziakm, @Roman-Koshelev, @chronoxor, @ShawnZhong, @russelltg, @glebm, @tmartin-gh, @Zhaojun-Liu, @louiswins and @mogemimi.
-
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 }
Thanks @marksantaniello.
-
Fixed handling of invalid UTF-8 (#3038, #3044, #3056). Thanks @phprus and @skeeto.
-
Improved Unicode support in
ostream
overloads ofprint
(#2994, #3001, #3025). Thanks @dimztimz. -
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. -
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.
-
Worked around problematic
std::string_view
constructors introduced in C++23 (#3030, #3050). Thanks @strega-nil-ms. -
Improve handling (exclusion) of recursive ranges (#2968, #2974). Thanks @Dani-Hub.
-
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.
-
Fixed issues with floating-point formatting on exotic platforms.
-
Improved the implementation of chrono formatting (#3010). Thanks @phprus.
-
Improved documentation (#2966, #3009, #3020, #3037). Thanks @mwinterb, @jcelerier and @remiburtin.
-
Improved build configuration (#2991, #2995, #3004, #3007, #3040). Thanks @dimztimz and @hwhsu1231.
-
Fixed various warnings and compilation issues (#2969, #2971, #2975, #2982, #2985, #2988, #2989, #3000, #3006, #3014, #3015, #3021, #3023, #3024, #3029, #3043, #3052, #3053, #3054). Thanks @h-friederich, @dimztimz, @olupton, @bernhardmgruber and @phprus.
-
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.
-
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.
-
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"); }
prints
Thanks @rbrugo.
-
Made
fmt::print
overload for text styles correctly handle UTF-8 (#2681, #2701). Thanks @AlexGuteniev. -
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.
-
Implemented escaping of wide strings in ranges (#2904). Thanks @phprus.
-
Added support for ranges with
begin
/end
found via the argument-dependent lookup (#2807). Thanks @rbrugo. -
Fixed formatting of certain kinds of ranges of ranges (#2787). Thanks @BRevzin.
-
Fixed handling of maps with element types other than
std::pair
(#2944). Thanks @BrukerJWD. -
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. -
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. -
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. -
Removed a redundant buffer resize when formatting to
std::ostream
(#2842, #2843). Thanks @jcelerier. -
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.
-
Improved documentation (#2706, #2712, #2789, #2803, #2805, #2815, #2924). Thanks @BRevzin, @Pokechu22, @setoye, @rtobar, @rbrugo, @anoonD and @leha-bot.
-
Improved build configuration (#2766, #2772, #2836, #2852, #2907, #2913, #2914). Thanks @kambala-decapitator, @mattiasljungstrom, @kieselnb, @nathannaveen and @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, @ivan-volnov, @VasiliPupkin256, @federico-busato, @barcharcraz, @jk-jeon, @HazardyKnusperkeks, @dalboris, @seanm, @gsjaardema, @timsong-cpp, @seanm, @frithrah, @chronoxor, @Agga, @madmaxoft, @JurajX, @phprus and @Dani-Hub.
- Restored ABI compatibility with version 8.0.x (#2695, #2696). Thanks @saraedum.
- Fixed chrono formatting on big endian systems (#2698, #2699). Thanks @phprus and @xvitaly.
- Fixed a linkage error with mingw (#2691, #2692). Thanks @rbberger.
-
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 and @toughengineer.
-
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. -
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 and @data-man.
-
Added experimental support for compile-time floating point formatting (#2426, #2470). It is currently limited to the header-only mode. Thanks @alexezeder.
-
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.
-
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"]
-
Added an experimental
?
specifier for escaping strings. (#2674). Thanks @BRevzin. -
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. -
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. -
Marked
format
,formatted_size
andto_string
as[[nodiscard]]
(#2612). @0x8000-0000. -
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.
-
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.
-
Resolved a lookup ambiguity with C++20 format-related functions due to ADL (#2639, #2641). Thanks @mkurdej.
-
Removed unnecessary inline namespace qualification (#2642, #2643). Thanks @mkurdej.
-
Implemented argument forwarding in
format_to_n
(#2462, #2463). Thanks @owent. -
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.
-
Improved
consteval
detection for MSVC (#2559). Thanks @DanielaE. -
Improved documentation (#2406, #2446, #2493, #2513, #2515, #2522, #2562, #2575, #2606, #2620, #2676). Thanks @sobolevn, @UnePierre, @zhsj, @phprus, @ericcurtin and @Lounarok.
-
Improved fuzzers and added a fuzzer for chrono timepoint formatting (#2461, #2469). @pauldreik,
-
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. -
Added the Bazel build system support (#2505, #2516). Thanks @Vertexwahn.
-
Improved build configuration and tests (#2437, #2558, #2648, #2650, #2663, #2677). Thanks @DanielaE, @alexezeder and @phprus.
-
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, @mwinterb, @cdacamar, @TrebledJ, @bodomartin, @cquammen, @white238, @mmarkeloff, @palacaze, @jcelerier, @mborn-adi, @BrukerJWD, @spyridon97, @phprus, @oliverlee, @joshessman-llnl, @akohlmey, @timkalu, @olupton, @Acretock, @alexezeder, @andrewcorrigan, @lucpelletier and @HazardyKnusperkeks.
- 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.
- Removed dead code in FP formatter ( #2398). Thanks @javierhonduco.
- Fixed various warnings and compilation issues (#2351, #2359, #2365, #2368, #2370, #2376, #2381, #2382, #2386, #2389, #2395, #2397, #2400, #2401, #2407). Thanks @zx2c4, @AidanSun05, @mattiasljungstrom, @joemmett, @erengy, @patlkli, @gsjaardema and @phprus.
-
Enabled compile-time format string checks 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.
-
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.
-
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.
-
Added format string compilation support to
fmt::print
(#2280, #2304). Thanks @alexezeder. -
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.
-
Made symbols private by default reducing shared library size (#2301). For example there was a ~15% reported reduction on one platform. Thanks @sergiud.
-
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. -
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.
-
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.
-
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. -
Deprecated an undocumented
format_to
overload that takesbasic_memory_buffer
. -
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. -
Made the hexfloat formatting use the right alignment by default (#2308, #2317). Thanks @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` and
make_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
'+'
specifier in localized formatting (#2133). -
Added support for the
's'
format specifier that gives textual representation ofbool
(#2094, #2109). For example:#include <fmt/core.h> int main() { fmt::print("{:s}", true); }
prints "true". Thanks @powercoderlol.
-
Made
fmt::ptr
work with function pointers (#2131). For example:#include <fmt/format.h> int main() { fmt::print("My main: {}\n", fmt::ptr(main)); }
Thanks @mikecrowe.
-
The undocumented support for specializing
formatter
for pointer types has been removed. -
Fixed
fmt::formatted_size
with format string compilation (#2141, #2161). Thanks @alexezeder. -
Fixed handling of empty format strings during format string compilation (#2042):
auto s = fmt::format(FMT_COMPILE(""));
Thanks @alexezeder.
-
Fixed handling of enums in
fmt::to_string
(#2036). -
Improved width computation (#2033, #2091). For example:
#include <fmt/core.h> int main() { fmt::print("{:-<10}{}\n", "你好", "世界"); fmt::print("{:-<10}{}\n", "hello", "world"); }
prints
on a modern terminal.
-
The experimental fast output stream (
fmt::ostream
) is now truncated by default for consistency withfopen
(#2018). For example:#include <fmt/os.h> int main() { fmt::ostream out1 = fmt::output_file("guide"); out1.print("Zaphod"); out1.close(); fmt::ostream out2 = fmt::output_file("guide"); out2.print("Ford"); }
writes "Ford" to the file "guide". To preserve the old file content if any pass
fmt::file::WRONLY | fmt::file::CREATE
flags tofmt::output_file
. -
Fixed moving of
fmt::ostream
that holds buffered data (#2197, #2198). Thanks @vtta. -
Replaced the
fmt::system_error
exception with a function of the same name that constructsstd::system_error
(#2266). -
Replaced the
fmt::windows_error
exception with a function of the same name that constructsstd::system_error
with the category returned byfmt::system_category()
(#2274, #2275). The latter is similar tostd::system_category
but correctly handles UTF-8. Thanks @phprus. -
Replaced
fmt::error_code
withstd::error_code
and made it formattable (#2269, #2270, #2273). Thanks @phprus. -
Added speech synthesis support (#2206).
-
Made
format_to
work with a memory buffer that has a custom allocator (#2300). Thanks @voxmea. -
Added
Allocator::max_size
support tobasic_memory_buffer
. (#1960). Thanks @phprus. -
Added wide string support to
fmt::join
(#2236). Thanks @crbrz. -
Made iterators passed to
formatter
specializations via a format context satisfy C++20std::output_iterator
requirements (#2156, #2158, #2195, #2204). Thanks @randomnetcat. -
Optimized the
printf
implementation (#1982, #1984, #2016, #2164). Thanks @rimathia and @moiwi. -
Improved detection of
constexpr
char_traits
(#2246, #2257). Thanks @phprus. -
Fixed writing to
stdout
when it is redirected toNUL
on Windows (#2080). -
Fixed exception propagation from iterators (#2097).
-
Improved
strftime
error handling (#2238, #2244). Thanks @yumeyao. -
Stopped using deprecated GCC UDL template extension.
-
Added
fmt/args.h
to the install target (#2096). -
Error messages are now passed to assert when exceptions are disabled (#2145). Thanks @NobodyXu.
-
Added the
FMT_MASTER_PROJECT
CMake option to control build and install targets when {fmt} is included viaadd_subdirectory
(#2098, #2100). Thanks @randomizedthinking. -
Improved build configuration (#2026, #2122). Thanks @luncliff and @ibaned.
-
Fixed various warnings and compilation issues (#1947, #1959, #1963, #1965, #1966, #1974, #1975, #1990, #2000, #2001, #2002, #2004, #2006, #2009, #2010, #2038, #2039, #2047, #2053, #2059, #2065, #2067, #2068, #2073, #2103, #2105, #2106, #2107, #2116, #2117, #2118, #2119, #2127, #2128, #2140, #2142, #2143, #2144, #2147, #2148, #2149, #2152, #2160, #2170, #2175, #2176, #2177, #2178, #2179, #2180, #2181, #2183, #2184, #2185, #2186, #2187, #2190, #2192, #2194, #2205, #2210, #2211, #2215, #2216, #2218, #2220, #2228, #2229, #2230, #2233, #2239, #2248, #2252, #2253, #2255, #2261, #2278, #2284, #2287, #2289, #2290, #2293, #2295, #2296, #2297, #2311, #2313, #2315, #2320, #2321, #2323, #2328, #2329, #2333, #2338, #2341). Thanks @darklukee, @fagg, @killerbot242, @jgopel, @yeswalrus, @Finkman, @HazardyKnusperkeks, @dkavolis, @concatime, @chronoxor, @summivox, @yNeo, @Apache-HB, @alexezeder, @toojays, @Brainy0207, @vadz, @imsherlock, @phprus, @white238, @yafshar, @BillyDonahue, @jstaahl, @denchat, @DanielaE, @ilyakurdyukov, @ilmai, @JessyDL, @sergiud, @mwinterb, @sven-herrmann, @jmelas, @twoixter, @crbrz and @upsj.
-
Improved documentation (#1986, #2051, #2057, #2081, #2084, #2312). Thanks @imba-tjd, @0x416c69 and @mordante.
-
Continuous integration and test improvements (#1969, #1991, #2020, #2110, #2114, #2196, #2217, #2247, #2256, #2336, #2346). Thanks @jgopel, @alexezeder and @DanielaE.
The change log for versions 0.8.0 - 7.1.3 is available here.