Releases: fmtlib/fmt
11.1.3
-
Fixed compilation on GCC 9.4 (#4313).
-
Worked around an internal compiler error when using C++20 modules with GCC 14.2 and earlier (#4295).
-
Worked around a bug in GCC 6 (#4318).
-
Fixed an issue caused by instantiating
formatter<const T>
(#4303, #4325). Thanks @timsong-cpp. -
Fixed formatting into
std::ostreambuf_iterator
when using format string compilation (#4309, #4312). Thanks @phprus. -
Restored a constraint on the map formatter so that it correctly reports as unformattable when the element is (#4326). Thanks @timsong-cpp.
-
Reduced the size of format specs (#4298).
-
Readded
args()
tofmt::format_context
(#4307, #4310). Thanks @Erroneous1. -
Fixed a pedantic mode error in the CMake config (#4327). Thanks @rlalik.
11.1.2
-
Fixed ABI compatibility with earlier 11.x versions (#4292).
-
Added
wchar_t
support to thestd::bitset
formatter (#4285, #4286, #4289, #4290). Thanks @phprus. -
Prefixed CMake components with
fmt-
to simplify usage of {fmt} viaadd_subdirectory
(#4283). -
Fixed a compilation error in chrono on nvcc (#4297, #4301). Thanks @breyerml.
-
Fixed various warnings (#4288, #4299). Thanks @GamesTrap and @edo9300.
11.1.1
11.1.0
-
Improved C++20 module support (#4081, #4083, #4084, #4152, #4153, #4169, #4190, #4234, #4239). Thanks @kamrann and @Arghnews.
-
Reduced debug (unoptimized) binary code size and the number of template instantiations when passing formatting arguments. For example, unoptimized binary code size for
fmt::print("{}", 42)
was reduced by ~40% on GCC and ~60% on clang (x86-64).GCC:
- Before: 161 instructions of which 105 are in reusable functions (godbolt).
- After: 116 instructions of which 60 are in reusable functions (godbolt).
Clang:
-
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(); }
-
Added width and alignment support to the formatter of
std::error_code
. -
Made
std::expected<void, E>
formattable (#4145, #4148). For example (godbolt):fmt::print("{}", std::expected<void, int>());
prints
expected()
Thanks @phprus.
-
Made
fmt::is_formattable<void>
SFINAE-friendly (#4147). -
Added support for
_BitInt
formatting when using clang (#4007, #4072, #4140, #4173, #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. -
Fixed compile-time formatting of some string types (#4065). Thanks @torshepherd.
-
Made compiled version of
fmt::format_to
work withstd::back_insert_iterator<std::vector<char>>
(#4206, #4211). 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
fmt::formatter<std::string_view>
for types with an implicit conversion tostd::string_view
(#4036, #4055). Thanks @Arghnews. -
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. -
Added support for UTF-32 code units greater than
0xFFFF
in fill (#4201). -
Fixed handling of legacy encodings on Windows with GCC (#4162).
-
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. -
Removed the ability to control locale usage via an undocumented
FMT_STATIC_THOUSANDS_SEPARATOR
in favor ofFMT_USE_LOCALE
. -
Renamed
FMT_EXCEPTIONS
toFMT_USE_EXCEPTIONS
for consistency with other similar macros. -
Improved include directory ordering to reduce the chance of including incorrect headers when using multiple versions of {fmt} (#4116). Thanks @cdzhan.
-
Made it possible to compile a subset of {fmt} without the C++ runtime.
-
Improved documentation and README (#4066, #4117, #4203, #4235). Thanks @zyctree and @nikola-sh.
-
Improved the documentation generator (#4110, #4115). Thanks @rturrado.
-
Fixed various warnings and compilation issues (#2708, #4091, #4109, #4113, #4125, #4129, #4130, #4131, #4132, #4133, #4144, #4150, #4158, #4159, #4160, #4170, #4177, #4187, #4188, #4194, #4200, #4205, #4207, #4208, #4210, #4220, #4231, #4232, #4233, #4236, #4267, #4271). Thanks @torsten48, @Arghnews, @tinfoilboy, @aminya, @Ottani, @zeroomega, @c4v4, @kongy, @vinayyadav3016, @sergio-nsk, @phprus and @YexuanXiao.
11.0.2
-
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).
11.0.1
-
Fixed version number in the inline namespace (#4047).
-
Fixed disabling Unicode support via CMake (#4051).
-
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.
11.0.0
-
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 (https://...
10.2.1
10.2.0
-
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. -
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).
10.1.1
-
Added formatters for
std::atomic
andatomic_flag
(#3574, #3594). Thanks @wangzw (Zhanwei Wang) and @AlexGuteniev (Alex Guteniev). -
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 (Mathew Benson).
-
Made
fmt::to_string
work with types that haveformat_as
overloads (#3575). Thanks @phprus (Vladislav Shchapov). -
Made
formatted_size
work with integral format specifiers at compile time (#3591). Thanks @elbeno (Ben Deane). -
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 (Joyce).
Pull Requests
- Configure OpenSSF Scorecard Action by @joycebrum in #3571
- to_string supports types with format_as by @phprus in #3575
- Add formatter for std::atomic by @wangzw in #3574
- Bump github/codeql-action from 2.2.4 to 2.21.4 by @dependabot in #3591
- Bump ossf/scorecard-action from 2.1.2 to 2.2.0 by @dependabot in #3592
- Bump actions/upload-artifact from 3.1.0 to 3.1.2 by @dependabot in #3593
- Fix
formatted_size
withFMT_COMPILE
and format specs by @elbeno in #3588 - fix issues #3598 by @YuHuanTin in #3599
- Fix for Compilation Error When Using FMT_MODULE by @MathewBensonCode in #3597
- Fix
FMT_NO_UNIQUE_ADDRESS
warning with clang-cl. by @lukester1975 in #3600 - Bump actions/checkout from 3.1.0 to 3.5.3 by @dependabot in #3602
- Fix for FMT_MODULE not compiling on GCC by @MathewBensonCode in #3605
atomic_flag
formatting by @AlexGuteniev in #3594
New Contributors
- @wangzw made their first contribution in #3574
- @elbeno made their first contribution in #3588
- @YuHuanTin made their first contribution in #3599
- @MathewBensonCode made their first contribution in #3597