- Improved debug codegen.
-
Fixed compatibility with non-POSIX systems (fmtlib#4054, fmtlib#4060).
-
Fixed performance regressions when using
std::back_insert_iterator
withfmt::format_to
(fmtlib#4070). -
Fixed handling of
std::generator
and move-only iterators (fmtlib#4053, fmtlib#4057). Thanks @Arghnews. -
Made
formatter<std::string_view>::parse
work with types convertible tostd::string_view
(fmtlib#4036, fmtlib#4055). Thanks @Arghnews. -
Made
volatile void*
formattable (fmtlib#4049, fmtlib#4056). Thanks @Arghnews. -
Made
Glib::ustring
not be confused withstd::string
(fmtlib#4052). -
Made
fmt::context
iterator compatible with STL algorithms that rely on iterator category (fmtlib#4079).
-
Fixed version number in the inline namespace (fmtlib#4047).
-
Fixed disabling Unicode support via CMake (fmtlib#4051).
-
Fixed deprecated
visit_format_arg
(fmtlib#4043). Thanks @nebkat. -
Fixed handling of a sign and improved the
std::complex
formater (fmtlib#4034, fmtlib#4050). Thanks @tesch1 and @phprus. -
Fixed ADL issues in
fmt::printf
when using C++20 (fmtlib#4042). Thanks @toge. -
Removed a redundant check in the formatter for
std::expected
(fmtlib#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 (fmtlib#3990, fmtlib#3991, fmtlib#3993, fmtlib#3994, fmtlib#3997, fmtlib#3998, fmtlib#4004, fmtlib#4005, fmtlib#4006, fmtlib#4013, fmtlib#4027, fmtlib#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 (fmtlib#3921, fmtlib#3928). Thanks @matt77hias. -
Exported
fmt::range_format
,fmt::range_format_kind
andfmt::compiled_string
from thefmt
module (fmtlib#3970, fmtlib#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 (fmtlib#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
(fmtlib#3834). Thanks @dominicpoeschko. -
Added a formatter for
std::complex
(fmtlib#1467, fmtlib#3886, fmtlib#3892, fmtlib#3900). Thanks @phprus. -
Added a formatter for
std::type_info
(fmtlib#3978). Thanks @matt77hias. -
Specialized
formatter
forstd::basic_string
types with custom traits and allocators (fmtlib#3938, fmtlib#3943). Thanks @dieram3. -
Added formatters for
std::chrono::day
,std::chrono::month
,std::chrono::year
andstd::chrono::year_month_day
(fmtlib#3758, fmtlib#3772, fmtlib#3906, fmtlib#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
(fmtlib#3794, fmtlib#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 (fmtlib#3976). Thanks @ZaheenJ. -
Fixed the scope of the
-
extension in chrono formatting so that it doesn't apply to subsequent specifiers (fmtlib#3811, fmtlib#3812). Thanks @phprus. -
Improved handling of
time_point::min()
(fmtlib#3282). -
Added support for character range formatting (fmtlib#3857, fmtlib#3863). Thanks @js324.
-
Added
string
anddebug_string
range formatters (fmtlib#3973, fmtlib#4024). Thanks @matt77hias. -
Enabled ADL for
begin
andend
infmt::join
(fmtlib#3813, fmtlib#3824). Thanks @bbolli. -
Made contiguous iterator optimizations apply to
std::basic_string
iterators (fmtlib#3798). Thanks @phprus. -
Added support for ranges with mutable
begin
andend
(fmtlib#3752, fmtlib#3800, fmtlib#3955). Thanks @tcbrindle and @Arghnews. -
Added support for move-only iterators to
fmt::join
(fmtlib#3802, fmtlib#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 (fmtlib#3839, fmtlib#3964). Thanks @Arghnews. -
Added an
fmt::formattable
concept (fmtlib#3974). Thanks @matt77hias. -
Added support for
__float128
(fmtlib#3494). -
Fixed rounding issues when formatting
long double
with fixed precision (fmtlib#3539). -
Made
fmt::isnan
not trigger floating-point exception for NaN values (fmtlib#3948, fmtlib#3951). Thanks @alexdewar. -
Removed dependency on
<memory>
forstd::allocator_traits
when possible (fmtlib#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 (fmtlib#4000, fmtlib#4001). Thanks @yujincheng08.
-
Made
fmt::iterator_buffer
's move constructornoexcept
(fmtlib#3808). Thanks @waywardmonkeys. -
Started enforcing that
formatter::format
is const for compatibility withstd::format
(fmtlib#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 (fmtlib#3846). Thanks @dalle. -
Fixed
fmt::group_digits
for negative integers (fmtlib#3891, fmtlib#3901). Thanks @phprus. -
Fixed handling of negative ids in
fmt::basic_format_args::get
(fmtlib#3945). Thanks @marlenecota. -
Improved named argument validation (fmtlib#3817).
-
Disabled copy construction/assignment for
fmt::format_arg_store
and fixed moved construction (fmtlib#3833). Thanks @ivafanas. -
Worked around a locale issue in RHEL/devtoolset (fmtlib#3858, fmtlib#3859). Thanks @g199209.
-
Added RTTI detection for MSVC (fmtlib#3821, fmtlib#3963). Thanks @edo9300.
-
Migrated the documentation from Sphinx to MkDocs.
-
Improved documentation and README (fmtlib#3775, fmtlib#3784, fmtlib#3788, fmtlib#3789, fmtlib#3793, fmtlib#3818, fmtlib#3820, fmtlib#3822, fmtlib#3843, fmtlib#3890, fmtlib#3894, fmtlib#3895, fmtlib#3905, fmtlib#3942, fmtlib#4008). Thanks @zencatalyst, WolleTD, @tupaschoal, @Dobiasd, @frank-weinberg, @bbolli, @phprus, @waywardmonkeys, @js324 and @tchaikov.
-
Improved CI and tests (fmtlib#3878, fmtlib#3883, fmtlib#3897, fmtlib#3979, fmtlib#3980, fmtlib#3988, fmtlib#4010, fmtlib#4012, fmtlib#4038). Thanks @vgorrX, @waywardmonkeys, @tchaikov and @phprus.
-
Fixed buffer overflow when using format string compilation with debug format and
std::back_insert_iterator
(fmtlib#3795, fmtlib#3797). Thanks @phprus. -
Improved Bazel support (fmtlib#3792, fmtlib#3801, fmtlib#3962, fmtlib#3965). Thanks @Vertexwahn.
-
Improved/fixed the CMake config (fmtlib#3777, fmtlib#3783, fmtlib#3847, fmtlib#3907). Thanks @phprus and @xTachyon.
-
Fixed various warnings and compilation issues (fmtlib#3685, fmtlib#3769, fmtlib#3796, fmtlib#3803, fmtlib#3806, fmtlib#3807, fmtlib#3809, fmtlib#3810, fmtlib#3830, fmtlib#3832, fmtlib#3835, fmtlib#3844, fmtlib#3854, fmtlib#3856, fmtlib#3865, fmtlib#3866, fmtlib#3880, fmtlib#3881, fmtlib#3884, fmtlib#3898, fmtlib#3899, fmtlib#3909, fmtlib#3917, fmtlib#3923, fmtlib#3924, fmtlib#3925, fmtlib#3930, fmtlib#3931, fmtlib#3933, fmtlib#3935, fmtlib#3937, fmtlib#3967, fmtlib#3968, fmtlib#3972, fmtlib#3983, fmtlib#3992, fmtlib#3995, fmtlib#4009, fmtlib#4023). Thanks @hmbj, @phprus, @res2k, @Baardi, @matt77hias, @waywardmonkeys, @hmbj, @yakra, @prlw1, @Arghnews, @mtillmann0, @ShifftC, @eepp, @jimmy-park and @ChristianGebhardt.
- Fixed ABI compatibility with earlier 10.x versions (fmtlib#3785, fmtlib#3786). Thanks @saraedum.
-
Added support for the
%j
specifier (the number of days) forstd::chrono::duration
(fmtlib#3643, fmtlib#3732). Thanks @intelfx. -
Added support for the chrono suffix for days and changed the suffix for minutes from "m" to the correct "min" (fmtlib#3662, fmtlib#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 (fmtlib#3725, fmtlib#3727). Thanks @cschreib. -
Added a formatter for
std::source_location
(fmtlib#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
(fmtlib#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
(fmtlib#3715, fmtlib#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 (fmtlib#3739). Thanks @tchaikov. -
Fixed formatting of invalid UTF-8 with precision (fmtlib#3284).
-
Fixed an inconsistency between
fmt::to_string
andfmt::format
(fmtlib#3684). -
Disallowed unsafe uses of
fmt::styled
(fmtlib#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 (fmtlib#3706). -
Disallowed the
c
specifier forbool
(fmtlib#3726, fmtlib#3734). Thanks @js324. -
Made the default formatting unlocalized in
fmt::ostream_formatter
for consistency with the rest of the library (fmtlib#3460). -
Fixed localized formatting in bases other than decimal (fmtlib#3693, fmtlib#3750). Thanks @js324.
-
Fixed a performance regression in experimental
fmt::ostream::print
(fmtlib#3674). -
Added synchronization with the underlying output stream when writing to the Windows console (fmtlib#3668, fmtlib#3688, fmtlib#3689). Thanks @Roman-Koshelev and @dimztimz.
-
Changed to only export
format_error
when {fmt} is built as a shared library (fmtlib#3626, fmtlib#3627). Thanks @phprus. -
Made
fmt::streamed
constexpr
. (fmtlib#3650). Thanks @muggenhor. -
Made
fmt::format_int
constexpr
(fmtlib#4031, fmtlib#4032). Thanks @dixlorenz. -
Enabled
consteval
on older versions of MSVC (fmtlib#3757). Thanks @phprus. -
Added an option to build without
wchar_t
support on Windows (fmtlib#3631, fmtlib#3636). Thanks @glebm. -
Improved build and CI configuration (fmtlib#3679, fmtlib#3701, fmtlib#3702, fmtlib#3749). Thanks @jcar87, @pklima and @tchaikov.
-
Fixed various warnings, compilation and test issues (fmtlib#3607, fmtlib#3610, fmtlib#3624, fmtlib#3630, fmtlib#3634, fmtlib#3638, fmtlib#3645, fmtlib#3646, fmtlib#3647, fmtlib#3652, fmtlib#3654, fmtlib#3663, fmtlib#3670, fmtlib#3680, fmtlib#3694, fmtlib#3695, fmtlib#3699, fmtlib#3705, fmtlib#3710, fmtlib#3712, fmtlib#3713, fmtlib#3714, fmtlib#3716, fmtlib#3723, fmtlib#3738, fmtlib#3740, fmtlib#3741, fmtlib#3743, fmtlib#3745, fmtlib#3747, fmtlib#3748, fmtlib#3751, fmtlib#3754, fmtlib#3755, fmtlib#3760, fmtlib#3762, fmtlib#3763, fmtlib#3764, fmtlib#3774, fmtlib#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 (fmtlib#2086, fmtlib#3637, fmtlib#3642, fmtlib#3653, fmtlib#3655, fmtlib#3661, fmtlib#3673, fmtlib#3677, fmtlib#3737, fmtlib#3742, fmtlib#3744). Thanks @idzm, @perlun, @joycebrum, @fennewald, @reinhardt1053, @GeorgeLS.
-
Updated CI dependencies (fmtlib#3615, fmtlib#3622, fmtlib#3623, fmtlib#3666, fmtlib#3696, fmtlib#3697, fmtlib#3759, fmtlib#3782).
- Added formatters for
std::atomic
andatomic_flag
(fmtlib#3574, fmtlib#3594). Thanks @wangzw and @AlexGuteniev. - Fixed an error about partial specialization of
formatter<string>
after instantiation when compiled with gcc and C++20 (fmtlib#3584). - Fixed compilation as a C++20 module with gcc and clang (fmtlib#3587, fmtlib#3597, fmtlib#3605). Thanks @MathewBensonCode.
- Made
fmt::to_string
work with types that haveformat_as
overloads (fmtlib#3575). Thanks @phprus. - Made
formatted_size
work with integral format specifiers at compile time (fmtlib#3591). Thanks @elbeno. - Fixed a warning about the
no_unique_address
attribute on clang-cl (fmtlib#3599). Thanks @lukester1975. - Improved compatibility with the legacy GBK encoding (fmtlib#3598, fmtlib#3599). Thanks @YuHuanTin.
- Added OpenSSF Scorecard analysis (fmtlib#3530, fmtlib#3571). Thanks @joycebrum.
- Updated CI dependencies (fmtlib#3591, fmtlib#3592, fmtlib#3593, fmtlib#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 (fmtlib#3133, fmtlib#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
(fmtlib#3485). Thanks @Minty-Meeo. -
Added formatters for proxy references to elements of
std::vector<bool>
andstd::bitset<N>
(fmtlib#3567, fmtlib#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
(fmtlib#3556, fmtlib#3561). Thanks @5chmidti. -
Fixed compilation when formatting durations not convertible from
std::chrono::seconds
(fmtlib#3430). Thanks @patlkli. -
Made the
formatter
specialization forchar*
const-correct (fmtlib#3432). Thanks @timsong-cpp. -
Made
{}
and{:}
handled consistently during compile-time checks (fmtlib#3526). -
Disallowed passing temporaries to
make_format_args
to improve API safety by preventing dangling references. -
Improved the compile-time error for unformattable types (fmtlib#3478). Thanks @BRevzin.
-
Improved the floating-point formatter (fmtlib#3448, fmtlib#3450). Thanks @florimond-collette.
-
Fixed handling of precision for
long double
larger than 64 bits. (fmtlib#3539, fmtlib#3564). -
Made floating-point and chrono tests less platform-dependent (fmtlib#3337, fmtlib#3433, fmtlib#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 (fmtlib#3551). Thanks @mjerabek. -
Made
FMT_THROW
assert even if assertions are disabled when compiling with exceptions disabled (fmtlib#3418, fmtlib#3439). Thanks @BRevzin. -
Made
format_as
andstd::filesystem::path
formatter work with exotic code unit types. (fmtlib#3457, fmtlib#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 (fmtlib#3468). Thanks @danakj.
-
Improved compatibility with VxWorks7 (fmtlib#3467). Thanks @wenshan1.
-
Improved documentation (fmtlib#3174, fmtlib#3423, fmtlib#3454, fmtlib#3458, fmtlib#3461, fmtlib#3487, fmtlib#3515). Thanks @zencatalyst, @rlalik and @mikecrowe.
-
Improved build and CI configurations (fmtlib#3449, fmtlib#3451, fmtlib#3452, fmtlib#3453, fmtlib#3459, fmtlib#3481, fmtlib#3486, fmtlib#3489, fmtlib#3496, fmtlib#3517, fmtlib#3523, fmtlib#3563). Thanks @joycebrum, @glebm, @phprus, @petrmanek, @setoye and @abouvier.
-
Fixed various warnings and compilation issues (fmtlib#3408, fmtlib#3424, fmtlib#3444, fmtlib#3446, fmtlib#3475, fmtlib#3482, fmtlib#3492, fmtlib#3493, fmtlib#3508, fmtlib#3509, fmtlib#3533, fmtlib#3542, fmtlib#3543, fmtlib#3540, fmtlib#3544, fmtlib#3548, fmtlib#3549, fmtlib#3550, fmtlib#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 (fmtlib#3262, fmtlib#2750, fmtlib#3269, fmtlib#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 (fmtlib#3179, fmtlib#3203). This removes the last usage ofs(n)printf
in {fmt}. Thanks @phprus. -
Fixed alignment of floating-point numbers with localization (fmtlib#3263, fmtlib#3272). Thanks @ShawnZhong.
-
Made handling of
#
consistent withstd::format
. -
Improved C++20 module support (fmtlib#3134, fmtlib#3254, fmtlib#3386, fmtlib#3387, fmtlib#3388, fmtlib#3392, fmtlib#3397, fmtlib#3399, fmtlib#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 (fmtlib#3237, fmtlib#3260, fmtlib#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 (fmtlib#2207, fmtlib#3117, fmtlib#3115, fmtlib#3143, fmtlib#3144, fmtlib#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
(fmtlib#3148). Thanks @SappyJoy -
Added support for
std::utc_time
(fmtlib#3098, fmtlib#3110). Thanks @patrickroocks. -
Switched formatting of
std::chrono::system_clock
from local time to UTC for compatibility with the standard (fmtlib#3199, fmtlib#3230). Thanks @ned14. -
Added support for
%Ez
and%Oz
to chrono formatters. (fmtlib#3220, fmtlib#3222). Thanks @phprus. -
Improved validation of format specifiers for
std::chrono::duration
(fmtlib#3219, fmtlib#3232). Thanks @ShawnZhong. -
Fixed formatting of time points before the epoch (fmtlib#3117, fmtlib#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 (fmtlib#2959, fmtlib#3271). Thanks @ShawnZhong.
-
Added a formatter for
std::exception
(fmtlib#2977, fmtlib#3012, fmtlib#3062, fmtlib#3076, fmtlib#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
. (fmtlib#3125). Thanks @phprus. -
Added formatters for standard container adapters:
std::priority_queue
,std::queue
andstd::stack
(fmtlib#3215, fmtlib#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
(fmtlib#1367, fmtlib#3303). Thanks @tom-huntington. -
Fixed formatting of valueless by exception variants (fmtlib#3347). Thanks @TheOmegaCarrot.
-
Made
fmt::ptr
acceptunique_ptr
with a custom deleter (fmtlib#3177). Thanks @hmbj. -
Fixed formatting of noncopyable ranges and nested ranges of chars (fmtlib#3158 fmtlib#3286, fmtlib#3290). Thanks @BRevzin.
-
Fixed issues with formatting of paths and ranges of paths (fmtlib#3319, fmtlib#3321 fmtlib#3322). Thanks @phprus.
-
Improved handling of invalid Unicode in paths.
-
Enabled compile-time checks on Apple clang 14 and later (fmtlib#3331). Thanks @cloyce.
-
Improved compile-time checks of named arguments (fmtlib#3105, fmtlib#3214). Thanks @rbrich.
-
Fixed formatting when both alignment and
0
are given (fmtlib#3236, fmtlib#3248). Thanks @ShawnZhong. -
Improved Unicode support in the experimental file API on Windows (fmtlib#3234, fmtlib#3293). Thanks @Fros1er.
-
Unified UTF transcoding (fmtlib#3416). Thanks @phprus.
-
Added support for UTF-8 digit separators via an experimental locale facet (fmtlib#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 (fmtlib#3084, fmtlib#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 (fmtlib#3241, fmtlib#3244). Thanks @phprus. -
Added
starts_with
to the fallbackstring_view
implementation (fmtlib#3080). Thanks @phprus. -
Added
fmt::basic_format_string::get()
for compatibility withbasic_format_string
(fmtlib#3111). Thanks @huangqinjin. -
Added
println
for compatibility with C++23 (fmtlib#3267). Thanks @ShawnZhong. -
Renamed the
FMT_EXPORT
macro for shared library usage toFMT_LIB_EXPORT
. -
Improved documentation (fmtlib#3108, fmtlib#3169, fmtlib#3243). fmtlib#3404, fmtlib#4002). Thanks @Cleroth, @Vertexwahn and @yujincheng08.
-
Improved build configuration and tests (fmtlib#3118, fmtlib#3120, fmtlib#3188, fmtlib#3189, fmtlib#3198, fmtlib#3205, fmtlib#3207, fmtlib#3210, fmtlib#3240, fmtlib#3256, fmtlib#3264, fmtlib#3299, fmtlib#3302, fmtlib#3312, fmtlib#3317, fmtlib#3328, fmtlib#3333, fmtlib#3369, fmtlib#3373, fmtlib#3395, fmtlib#3406, fmtlib#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 (
{:}
) (fmtlib#3086). Thanks @oxidase. -
Worked around a broken implementation of
std::is_constant_evaluated
in some versions of libstdc++ on clang (fmtlib#3247, fmtlib#3281). Thanks @phprus. -
Fixed formatting of volatile variables (fmtlib#3068).
-
Fixed various warnings and compilation issues (fmtlib#3057, fmtlib#3066, fmtlib#3072, fmtlib#3082, fmtlib#3091, fmtlib#3092, fmtlib#3093, fmtlib#3095, fmtlib#3096, fmtlib#3097, fmtlib#3128, fmtlib#3129, fmtlib#3137, fmtlib#3139, fmtlib#3140, fmtlib#3142, fmtlib#3149, fmtlib#3150, fmtlib#3154, fmtlib#3163, fmtlib#3178, fmtlib#3184, fmtlib#3196, fmtlib#3204, fmtlib#3206, fmtlib#3208, fmtlib#3213, fmtlib#3216, fmtlib#3224, fmtlib#3226, fmtlib#3228, fmtlib#3229, fmtlib#3259, fmtlib#3274, fmtlib#3287, fmtlib#3288, fmtlib#3292, fmtlib#3295, fmtlib#3296, fmtlib#3298, fmtlib#3325, fmtlib#3326, fmtlib#3334, fmtlib#3342, fmtlib#3343, fmtlib#3351, fmtlib#3352, fmtlib#3362, fmtlib#3365, fmtlib#3366, fmtlib#3374, fmtlib#3377, fmtlib#3378, fmtlib#3381, fmtlib#3398, fmtlib#3413, fmtlib#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 (fmtlib#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 (fmtlib#3038, fmtlib#3044, fmtlib#3056). Thanks @phprus and @skeeto.
-
Improved Unicode support in
ostream
overloads ofprint
(fmtlib#2994, fmtlib#3001, fmtlib#3025). Thanks @dimztimz. -
Fixed handling of the sign specifier in localized formatting on systems with 32-bit
wchar_t
(fmtlib#3041). -
Added support for wide streams to
fmt::streamed
(fmtlib#2994). Thanks @phprus. -
Added the
n
specifier that disables the output of delimiters when formatting ranges (fmtlib#2981, fmtlib#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 (fmtlib#3030, fmtlib#3050). Thanks @strega-nil-ms. -
Improve handling (exclusion) of recursive ranges (fmtlib#2968, fmtlib#2974). Thanks @Dani-Hub.
-
Improved error reporting in format string compilation (fmtlib#3055).
-
Improved the implementation of Dragonbox, the algorithm used for the default floating-point formatting (fmtlib#2984). Thanks @jk-jeon.
-
Fixed issues with floating-point formatting on exotic platforms.
-
Improved the implementation of chrono formatting (fmtlib#3010). Thanks @phprus.
-
Improved documentation (fmtlib#2966, fmtlib#3009, fmtlib#3020, fmtlib#3037). Thanks @mwinterb, @jcelerier and @remiburtin.
-
Improved build configuration (fmtlib#2991, fmtlib#2995, fmtlib#3004, fmtlib#3007, fmtlib#3040). Thanks @dimztimz and @hwhsu1231.
-
Fixed various warnings and compilation issues (fmtlib#2969, fmtlib#2971, fmtlib#2975, fmtlib#2982, fmtlib#2985, fmtlib#2988, fmtlib#2989, fmtlib#3000, fmtlib#3006, fmtlib#3014, fmtlib#3015, fmtlib#3021, fmtlib#3023, fmtlib#3024, fmtlib#3029, fmtlib#3043, fmtlib#3052, fmtlib#3053, fmtlib#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 (fmtlib#2713, fmtlib#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 (fmtlib#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 (fmtlib#2865, fmtlib#2902, fmtlib#2917, fmtlib#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 (fmtlib#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 (fmtlib#2681, fmtlib#2701). Thanks @AlexGuteniev. -
Fixed Unicode handling when writing to an ostream.
-
Added support for nested specifiers to range formatting (fmtlib#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 (fmtlib#2904). Thanks @phprus.
-
Added support for ranges with
begin
/end
found via the argument-dependent lookup (fmtlib#2807). Thanks @rbrugo. -
Fixed formatting of certain kinds of ranges of ranges (fmtlib#2787). Thanks @BRevzin.
-
Fixed handling of maps with element types other than
std::pair
(fmtlib#2944). Thanks @BrukerJWD. -
Made tuple formatter enabled only if elements are formattable (fmtlib#2939, fmtlib#2940). Thanks @jehelset.
-
Made
fmt::join
compatible with format string compilation (fmtlib#2719, fmtlib#2720). Thanks @phprus. -
Made compile-time checks work with named arguments of custom types and
std::ostream
print
overloads (fmtlib#2816, fmtlib#2817, fmtlib#2819). Thanks @timsong-cpp. -
Removed
make_args_checked
because it is no longer needed for compile-time checks (fmtlib#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
(fmtlib#2733). Thanks @arogge. -
Removed a redundant buffer resize when formatting to
std::ostream
(fmtlib#2842, fmtlib#2843). Thanks @jcelerier. -
Made precision computation for strings consistent with width (fmtlib#2888).
-
Fixed handling of locale separators in floating point formatting (fmtlib#2830).
-
Made sign specifiers work with
__int128_t
(fmtlib#2773). -
Improved support for systems such as CHERI with extra data stored in pointers (fmtlib#2932). Thanks @davidchisnall.
-
Improved documentation (fmtlib#2706, fmtlib#2712, fmtlib#2789, fmtlib#2803, fmtlib#2805, fmtlib#2815, fmtlib#2924). Thanks @BRevzin, @Pokechu22, @setoye, @rtobar, @rbrugo, @anoonD and @leha-bot.
-
Improved build configuration (fmtlib#2766, fmtlib#2772, fmtlib#2836, fmtlib#2852, fmtlib#2907, fmtlib#2913, fmtlib#2914). Thanks @kambala-decapitator, @mattiasljungstrom, @kieselnb, @nathannaveen and @Vertexwahn.
-
Fixed various warnings and compilation issues (fmtlib#2408, fmtlib#2507, fmtlib#2697, fmtlib#2715, fmtlib#2717, fmtlib#2722, fmtlib#2724, fmtlib#2725, fmtlib#2726, fmtlib#2728, fmtlib#2732, fmtlib#2738, fmtlib#2742, fmtlib#2744, fmtlib#2745, fmtlib#2746, fmtlib#2754, fmtlib#2755, fmtlib#2757, fmtlib#2758, fmtlib#2761, fmtlib#2762, fmtlib#2763, fmtlib#2765, fmtlib#2769, fmtlib#2770, fmtlib#2771, fmtlib#2777, fmtlib#2779, fmtlib#2782, fmtlib#2783, fmtlib#2794, fmtlib#2796, fmtlib#2797, fmtlib#2801, fmtlib#2802, fmtlib#2808, fmtlib#2818, fmtlib#2819, fmtlib#2829, fmtlib#2835, fmtlib#2848, fmtlib#2860, fmtlib#2861, fmtlib#2882, fmtlib#2886, fmtlib#2891, fmtlib#2892, fmtlib#2895, fmtlib#2896, fmtlib#2903, fmtlib#2906, fmtlib#2908, fmtlib#2909, fmtlib#2920, fmtlib#2922, fmtlib#2927, fmtlib#2929, fmtlib#2936, fmtlib#2937, fmtlib#2938, fmtlib#2951, fmtlib#2954, fmtlib#2957, fmtlib#2958, fmtlib#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 (fmtlib#2695, fmtlib#2696). Thanks @saraedum.
- Fixed chrono formatting on big endian systems (fmtlib#2698, fmtlib#2699). Thanks @phprus and @xvitaly.
- Fixed a linkage error with mingw (fmtlib#2691, fmtlib#2692). Thanks @rbberger.
-
Optimized chrono formatting (fmtlib#2500, fmtlib#2537, fmtlib#2541, fmtlib#2544, fmtlib#2550, fmtlib#2551, fmtlib#2576, fmtlib#2577, fmtlib#2586, fmtlib#2591, fmtlib#2594, fmtlib#2602, fmtlib#2617, fmtlib#2628, fmtlib#2633, fmtlib#2670, fmtlib#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 (fmtlib#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 (fmtlib#2587, fmtlib#2588). Thanks @lukester1975.
-
Fixed an overflow on invalid inputs in the
tm
formatter (fmtlib#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 (fmtlib#2394):
blink.mp4
Thanks @benit8 and @data-man.
-
Added experimental support for compile-time floating point formatting (fmtlib#2426, fmtlib#2470). It is currently limited to the header-only mode. Thanks @alexezeder.
-
Added UDL-based named argument support to compile-time format string checks (fmtlib#2640, fmtlib#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. (fmtlib#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 (fmtlib#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 (fmtlib#1841).
-
Deprecated implicit conversion of
[const] signed char*
and[const] unsigned char*
to C strings. -
Deprecated
_format
, a legacy UDL-based format API (fmtlib#2646). Thanks @alexezeder. -
Marked
format
,formatted_size
andto_string
as[[nodiscard]]
(fmtlib#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 (fmtlib#2598, fmtlib#2609, fmtlib#2610). Thanks @AlexGuteniev.
-
Optimized writing to a contiguous buffer with
format_to_n
(fmtlib#2489). Thanks @Roman-Koshelev. -
Optimized writing to non-
char
buffers (fmtlib#2477). Thanks @Roman-Koshelev. -
Decimal point is now localized when using the
L
specifier. -
Improved floating point formatter implementation (fmtlib#2498, fmtlib#2499). Thanks @Roman-Koshelev.
-
Fixed handling of very large precision in fixed format (fmtlib#2616).
-
Made a table of cached powers used in FP formatting static (fmtlib#2509). Thanks @jk-jeon.
-
Resolved a lookup ambiguity with C++20 format-related functions due to ADL (fmtlib#2639, fmtlib#2641). Thanks @mkurdej.
-
Removed unnecessary inline namespace qualification (fmtlib#2642, fmtlib#2643). Thanks @mkurdej.
-
Implemented argument forwarding in
format_to_n
(fmtlib#2462, fmtlib#2463). Thanks @owent. -
Fixed handling of implicit conversions in
fmt::to_string
and format string compilation (fmtlib#2565). -
Changed the default access mode of files created by
fmt::output_file
to-rw-r--r--
for consistency withfopen
(fmtlib#2530). -
Make
fmt::ostream::flush
public (fmtlib#2435). -
Improved C++14/17 attribute detection (fmtlib#2615). Thanks @AlexGuteniev.
-
Improved
consteval
detection for MSVC (fmtlib#2559). Thanks @DanielaE. -
Improved documentation (fmtlib#2406, fmtlib#2446, fmtlib#2493, fmtlib#2513, fmtlib#2515, fmtlib#2522, fmtlib#2562, fmtlib#2575, fmtlib#2606, fmtlib#2620, fmtlib#2676). Thanks @sobolevn, @UnePierre, @zhsj, @phprus, @ericcurtin and @Lounarok.
-
Improved fuzzers and added a fuzzer for chrono timepoint formatting (fmtlib#2461, fmtlib#2469). @pauldreik,
-
Added the
FMT_SYSTEM_HEADERS
CMake option setting which marks {fmt}'s headers as system. It can be used to suppress warnings (fmtlib#2644, fmtlib#2651). Thanks @alexezeder. -
Added the Bazel build system support (fmtlib#2505, fmtlib#2516). Thanks @Vertexwahn.
-
Improved build configuration and tests (fmtlib#2437, fmtlib#2558, fmtlib#2648, fmtlib#2650, fmtlib#2663, fmtlib#2677). Thanks @DanielaE, @alexezeder and @phprus.
-
Fixed various warnings and compilation issues (fmtlib#2353, fmtlib#2356, fmtlib#2399, fmtlib#2408, fmtlib#2414, fmtlib#2427, fmtlib#2432, fmtlib#2442, fmtlib#2434, fmtlib#2439, fmtlib#2447, fmtlib#2450, fmtlib#2455, fmtlib#2465, fmtlib#2472, fmtlib#2474, fmtlib#2476, fmtlib#2478, fmtlib#2479, fmtlib#2481, fmtlib#2482, fmtlib#2483, fmtlib#2490, fmtlib#2491, fmtlib#2510, fmtlib#2518, fmtlib#2528, fmtlib#2529, fmtlib#2539, fmtlib#2540, fmtlib#2545, fmtlib#2555, fmtlib#2557, fmtlib#2570, fmtlib#2573, fmtlib#2582, fmtlib#2605, fmtlib#2611, fmtlib#2647, fmtlib#2627, fmtlib#2630, fmtlib#2635, fmtlib#2638, fmtlib#2653, fmtlib#2654, fmtlib#2661, fmtlib#2664, fmtlib#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 (fmtlib#2374).
- Added a missing presentation type check for
std::string
(fmtlib#2402). - Fixed a linkage error when mixing code built with clang and gcc (fmtlib#2377).
- Fixed documentation issues (fmtlib#2396, fmtlib#2403, fmtlib#2406). Thanks @mkurdej.
- Removed dead code in FP formatter ( fmtlib#2398). Thanks @javierhonduco.
- Fixed various warnings and compilation issues (fmtlib#2351, fmtlib#2359, fmtlib#2365, fmtlib#2368, fmtlib#2370, fmtlib#2376, fmtlib#2381, fmtlib#2382, fmtlib#2386, fmtlib#2389, fmtlib#2395, fmtlib#2397, fmtlib#2400, fmtlib#2401, fmtlib#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 (fmtlib#2019, fmtlib#2044, fmtlib#2056, fmtlib#2072, fmtlib#2075, fmtlib#2078, fmtlib#2129, fmtlib#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 (fmtlib#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 (fmtlib#2043, fmtlib#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 (fmtlib#2243, fmtlib#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
(fmtlib#2280, fmtlib#2304). Thanks @alexezeder. -
Added initial support for compiling {fmt} as a C++20 module (fmtlib#2235, fmtlib#2240, fmtlib#2260, fmtlib#2282, fmtlib#2283, fmtlib#2288, fmtlib#2298, fmtlib#2306, fmtlib#2307, fmtlib#2309, fmtlib#2318, fmtlib#2324, fmtlib#2332, fmtlib#2340). Thanks @DanielaE.
-
Made symbols private by default reducing shared library size (fmtlib#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 (fmtlib#1998). -
Added support of ranges with non-const
begin
/end
(fmtlib#1953). Thanks @kitegi. -
Added support of
std::byte
and other formattable types tofmt::join
(fmtlib#1981, fmtlib#2040, fmtlib#2050, fmtlib#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
(fmtlib#2319, fmtlib#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 (fmtlib#2337, fmtlib#2349, fmtlib#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
(fmtlib#2327). -
Added support for time points with arbitrary durations (fmtlib#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 (fmtlib#2305, fmtlib#2310). Thanks @Liedtke. -
Made the hexfloat formatting use the right alignment by default (fmtlib#2308, fmtlib#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 (fmtlib#2133). -
Added support for the
's'
format specifier that gives textual representation ofbool
(fmtlib#2094, fmtlib#2109). For example:#include <fmt/core.h> int main() { fmt::print("{:s}", true); }
prints "true". Thanks @powercoderlol.
-
Made
fmt::ptr
work with function pointers (fmtlib#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 (fmtlib#2141, fmtlib#2161). Thanks @alexezeder. -
Fixed handling of empty format strings during format string compilation (fmtlib#2042):
auto s = fmt::format(FMT_COMPILE(""));
Thanks @alexezeder.
-
Fixed handling of enums in
fmt::to_string
(fmtlib#2036). -
Improved width computation (fmtlib#2033, fmtlib#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
(fmtlib#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 (fmtlib#2197, fmtlib#2198). Thanks @vtta. -
Replaced the
fmt::system_error
exception with a function of the same name that constructsstd::system_error
(fmtlib#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()
(fmtlib#2274, fmtlib#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 (fmtlib#2269, fmtlib#2270, fmtlib#2273). Thanks @phprus. -
Added speech synthesis support (fmtlib#2206).
-
Made
format_to
work with a memory buffer that has a custom allocator (fmtlib#2300). Thanks @voxmea. -
Added
Allocator::max_size
support tobasic_memory_buffer
. (fmtlib#1960). Thanks @phprus. -
Added wide string support to
fmt::join
(fmtlib#2236). Thanks @crbrz. -
Made iterators passed to
formatter
specializations via a format context satisfy C++20std::output_iterator
requirements (fmtlib#2156, fmtlib#2158, fmtlib#2195, fmtlib#2204). Thanks @randomnetcat. -
Optimized the
printf
implementation (fmtlib#1982, fmtlib#1984, fmtlib#2016, fmtlib#2164). Thanks @rimathia and @moiwi. -
Improved detection of
constexpr
char_traits
(fmtlib#2246, fmtlib#2257). Thanks @phprus. -
Fixed writing to
stdout
when it is redirected toNUL
on Windows (fmtlib#2080). -
Fixed exception propagation from iterators (fmtlib#2097).
-
Improved
strftime
error handling (fmtlib#2238, fmtlib#2244). Thanks @yumeyao. -
Stopped using deprecated GCC UDL template extension.
-
Added
fmt/args.h
to the install target (fmtlib#2096). -
Error messages are now passed to assert when exceptions are disabled (fmtlib#2145). Thanks @NobodyXu.
-
Added the
FMT_MASTER_PROJECT
CMake option to control build and install targets when {fmt} is included viaadd_subdirectory
(fmtlib#2098, fmtlib#2100). Thanks @randomizedthinking. -
Improved build configuration (fmtlib#2026, fmtlib#2122). Thanks @luncliff and @ibaned.
-
Fixed various warnings and compilation issues (fmtlib#1947, fmtlib#1959, fmtlib#1963, fmtlib#1965, fmtlib#1966, fmtlib#1974, fmtlib#1975, fmtlib#1990, fmtlib#2000, fmtlib#2001, fmtlib#2002, fmtlib#2004, fmtlib#2006, fmtlib#2009, fmtlib#2010, fmtlib#2038, fmtlib#2039, fmtlib#2047, fmtlib#2053, fmtlib#2059, fmtlib#2065, fmtlib#2067, fmtlib#2068, fmtlib#2073, fmtlib#2103, fmtlib#2105, fmtlib#2106, fmtlib#2107, fmtlib#2116, fmtlib#2117, fmtlib#2118, fmtlib#2119, fmtlib#2127, fmtlib#2128, fmtlib#2140, fmtlib#2142, fmtlib#2143, fmtlib#2144, fmtlib#2147, fmtlib#2148, fmtlib#2149, fmtlib#2152, fmtlib#2160, fmtlib#2170, fmtlib#2175, fmtlib#2176, fmtlib#2177, fmtlib#2178, fmtlib#2179, fmtlib#2180, fmtlib#2181, fmtlib#2183, fmtlib#2184, fmtlib#2185, fmtlib#2186, fmtlib#2187, fmtlib#2190, fmtlib#2192, fmtlib#2194, fmtlib#2205, fmtlib#2210, fmtlib#2211, fmtlib#2215, fmtlib#2216, fmtlib#2218, fmtlib#2220, fmtlib#2228, fmtlib#2229, fmtlib#2230, fmtlib#2233, fmtlib#2239, fmtlib#2248, fmtlib#2252, fmtlib#2253, fmtlib#2255, fmtlib#2261, fmtlib#2278, fmtlib#2284, fmtlib#2287, fmtlib#2289, fmtlib#2290, fmtlib#2293, fmtlib#2295, fmtlib#2296, fmtlib#2297, fmtlib#2311, fmtlib#2313, fmtlib#2315, fmtlib#2320, fmtlib#2321, fmtlib#2323, fmtlib#2328, fmtlib#2329, fmtlib#2333, fmtlib#2338, fmtlib#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 (fmtlib#1986, fmtlib#2051, fmtlib#2057, fmtlib#2081, fmtlib#2084, fmtlib#2312). Thanks @imba-tjd, @0x416c69 and @mordante.
-
Continuous integration and test improvements (fmtlib#1969, fmtlib#1991, fmtlib#2020, fmtlib#2110, fmtlib#2114, fmtlib#2196, fmtlib#2217, fmtlib#2247, fmtlib#2256, fmtlib#2336, fmtlib#2346). Thanks @jgopel, @alexezeder and @DanielaE.
The change log for versions 0.8.0 - 7.1.3 is available here.