Releases: fmtlib/fmt
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
10.1.0
-
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 (Vladislav Shchapov) and @felix642 (Félix-Antoine Constantin).
-
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 (Patrick Geltinger). -
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 (Barry Revzin).
-
Improved the floating-point formatter (#3448, #3450). Thanks @florimond-collette (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 (Vladislav Shchapov).
-
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 (Martin Jeřábek). -
Made
FMT_THROW
assert even if assertions are disabled when compiling with exceptions disabled (#3418, #3439). Thanks @BRevzin (Barry Revzin). -
Added support for the
?
format specifier tostd::filesystem::path
and made the default unescaped for consistency with strings. -
Made
format_as
andstd::filesystem::path
formatter work with exotic code unit types. (#3457, #3476). Thanks @gix (Nico Rieck), @hmbj (Hans-Martin B. Jensen). -
Deprecated the wide stream overload of
printf
. -
Removed unused
basic_printf_parse_context
. -
Improved RTTI detection used when formatting exceptions (#3468). Thanks @danakj (Dana Jansens).
-
Improved compatibility with VxWorks7 (#3467). Thanks @wenshan1 (Bin Lan).
-
Improved documentation (#3174, #3423, #3454, #3458, #3461, #3487, #3515). Thanks @zencatalyst (Kasra Hashemi), @rlalik, @mikecrowe (Mike Crowe).
-
Improved build and CI configurations (#3449, #3451, #3452, #3453, #3459, #3481, #3486, #3489, #3496, #3517, #3523, #3563). Thanks @joycebrum (Joyce), @glebm (Gleb Mazovetskiy), @phprus (Vladislav Shchapov), @petrmanek (Petr Mánek), @setoye (Alta), @abouvier (Alexandre Bouvier).
-
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 (Arnaud Desitter), @hmbj (Hans-Martin B. Jensen), @Minty-Meeo, @phprus (Vladislav Shchapov), @TobiSchluter (Tobias Schlüter), @kieranclancy (Kieran Clancy), @alexeedm (Dmitry Alexeev), @jurihock (Jürgen Hock), @Ozomahtli, @razaqq.
Pull Requests
- Fix time_point formatting for durations with certain ratios by @patlkli in #3430
- Make hex float test more stable by @phprus in #3434
- Always assert in FMT_THROW by @brevzin in #3439
- format-inl.h: address implicit int to bool conversion by @adesitter in #3446
- remove code duplication by @florimond-collette in #3448
- replace mod_inv_25 by explicit value as a fix for VS warning C4307 by @florimond-collette in #3450
- Fix parameter type of formatter<char*> by @timsong-cpp in #3432
- Hash pin Github Workflows by @joycebrum in #3451
- Create dependabot.yml by @joycebrum in #3452
- Update README.rst by @zencatalyst in #3454
- CMake: Do not fail on unknown compiler features by @glebm in #3453
- Fix example for user-defined types in documentation for 10.0.0 by @rlalik in #3461
- Make constexpr ceil by @phprus in #3459
- Pass correct Char to base format_as formatter by @gix in #3457
- Add VxWorks7 user space and kernel space support by @wenshan1 in #3467
- Only use typeid() in std.h when it is available by @danakj in #3468
- Fix MSVC warning in std::chrono::time_point formatter by @hmbj in #3475
- Use correct Char type in std::filesystem::path formatter by @hmbj in #3476
- Use FMT_TRY and FMT_CATCH in std.h by @Minty-Meeo in #3482
- Bump actions/checkout from 3.5.2 to 3.5.3 by @dependabot in #3486
- Give basic_memory_buffer allocator [[no_unique_address]] by @Minty-Meeo in #3485
- Fix for issue #3492 by @phprus in #3493
- Revert ae25f79 to restore capability to
cmake --install
when included as a subproject by @petrmanek in #3496 - Fix typo in assert message. by @TobiSchluter in #3508
- README: Add link to merged clang-tidy check by @mikecrowe in #3515
- Trying to improve errors in the unformattable case. by @brevzin in #3478
- fix missing header files when using CMake install by @setoye in #3523
- Fix format_string_checker initialisation order by @kieranclancy in #3542
- Turn off error-producing NVCC workaround when using c++20 by @alexeedm in #3544
- Remove std::copy usage. by @Ozomahtli in #3550
- expose detail::throw_format_error by @mjerabek in #3551
- Use the U literal for unsigned integer constants. by @jurihock in #3549
- Add missing inline specifier by @razaqq in #3552
- cmake: fix FMT_PKGCONFIG_DIR path by @abouvier in #3563
- fix ambiguous formatter lookup for flat_set by @5chmidti in #3561
- Added formatter for bit_reference-like types by @phprus in #3570
New Contributors
- @adesitter made their first contribution in #3446
- @florimond-collette made their first contribution in #3448
- @zencatalyst made their first contribution in #3454
- @rlalik made their first contribution in #3461
- @gix made their first contribution in #3457
- @wenshan1 made their first contribution in #3467
- @danakj made their first contribution in #3468
- @Minty-Meeo made their first contribution in #3482
- @dependabot made their first contribution in #3486
- @petrmanek made their first contr...
10.0.0
-
Replaced Grisu with a new floating-point formatting algorithm for given precision (#3262, #2750, #3269, #3276). The new algorithm is based on Dragonbox already used for the shortest representation and gives substantial performance improvement:
-
Red: new algorithm
-
Green: new algorithm with
FMT_USE_FULL_CACHE_DRAGONBOX
defined to 1 -
Blue: old algorithm
Thanks @jk-jeon (Junekey Jeon).
-
-
Replaced
snprintf
-based hex float formatter with an internal implementation (#3179, #3203). This removes the last usage ofs(n)printf
in {fmt}. Thanks @phprus (Vladislav Shchapov). -
Fixed alignment of floating-point numbers with localization (#3263, #3272). Thanks @ShawnZhong (Shawn Zhong).
-
Made handling of
#
consistent withstd::format
. -
Improved C++20 module support (#3134, #3254, #3386, #3387, #3388, #3392, #3397, #3399, #3400). Thanks @laitingsheng (Tinson Lai), @Orvid (Orvid King), @DanielaE (Daniela Engert). Switched to the modules CMake library which allows building {fmt} as a C++20 module with clang:
CXX=clang++ cmake -DFMT_MODULE=ON . make
-
Made
format_as
work with any user-defined type and not just enums. For example (godbolt):#include <fmt/format.h> struct floaty_mc_floatface { double value; }; auto format_as(floaty_mc_floatface f) { return f.value; } int main() { fmt::print("{:8}\n", floaty_mc_floatface{0.42}); // prints " 0.42" }
-
Removed deprecated implicit conversions for enums and conversions to primitive types for compatibility with
std::format
and to prevent potential ODR violations. Useformat_as
instead. -
Added support for fill, align and width to the time point formatter (#3237, #3260, #3275). For example (godbolt):
#include <fmt/chrono.h> int main() { // prints " 2023" fmt::print("{:>8%Y}\n", std::chrono::system_clock::now()); }
Thanks @ShawnZhong (Shawn Zhong).
-
Implemented formatting of subseconds (#2207, #3117, #3115, #3143, #3144, #3349). For example (godbolt):
#include <fmt/chrono.h> int main() { // prints 01.234567 fmt::print("{:%S}\n", std::chrono::microseconds(1234567)); }
Thanks @patrickroocks (Patrick Roocks) @phprus (Vladislav Shchapov), @BRevzin (Barry Revzin).
-
Added precision support to
%S
(#3148). Thanks @SappyJoy (Stepan Ponomaryov) -
Added support for
std::utc_time
(#3098, #3110). Thanks @patrickroocks (Patrick Roocks). -
Switched formatting of
std::chrono::system_clock
from local time to UTC for compatibility with the standard (#3199, #3230). Thanks @ned14 (Niall Douglas). -
Added support for
%Ez
and%Oz
to chrono formatters. (#3220, #3222). Thanks @phprus (Vladislav Shchapov). -
Improved validation of format specifiers for
std::chrono::duration
(#3219, #3232). Thanks @ShawnZhong (Shawn Zhong). -
Fixed formatting of time points before the epoch (#3117, #3261). For example (godbolt):
#include <fmt/chrono.h> int main() { auto t = std::chrono::system_clock::from_time_t(0) - std::chrono::milliseconds(250); fmt::print("{:%S}\n", t); // prints 59.750000000 }
Thanks @ShawnZhong (Shawn Zhong).
-
Experimental: implemented glibc extension for padding seconds, minutes and hours (#2959, #3271). Thanks @ShawnZhong (Shawn Zhong).
-
Added a formatter for
std::exception
(#2977, #3012, #3062, #3076, #3119). For example (godbolt):#include <fmt/std.h> #include <vector> int main() { try { std::vector<bool>().at(0); } catch(const std::exception& e) { fmt::print("{}", e); } }
prints:
vector<bool>::_M_range_check: __n (which is 0) >= this->size() (which is 0)
on libstdc++. Thanks @zach2good (Zach Toogood) and @phprus (Vladislav Shchapov).
-
Moved
std::error_code
formatter fromfmt/os.h
tofmt/std.h
. (#3125). Thanks @phprus (Vladislav Shchapov). -
Added formatters for standard container adapters:
std::priority_queue
,std::queue
andstd::stack
(#3215, #3279). For example (godbolt):#include <fmt/ranges.h> #include <stack> #include <vector> int main() { auto s = std::stack<bool, std::vector<bool>>(); for (auto b: {true, false, true}) s.push(b); fmt::print("{}\n", s); // prints [true, false, true] }
Thanks @ShawnZhong (Shawn Zhong).
-
Added a formatter for
std::optional
tofmt/std.h
. Thanks @tom-huntington. -
Fixed formatting of valueless by exception variants (#3347). Thanks @TheOmegaCarrot.
-
Made
fmt::ptr
acceptunique_ptr
with a custom deleter (#3177). Thanks @hmbj (Hans-Martin B. Jensen). -
Fixed formatting of noncopyable ranges and nested ranges of chars (#3158 #3286, #3290). Thanks @BRevzin (Barry Revzin).
-
Fixed issues with formatting of paths and ranges of paths (#3319, #3321 #3322). Thanks @phprus (Vladislav Shchapov).
-
Improved handling of invalid Unicode in paths.
-
Enabled compile-time checks on Apple clang 14 and later (#3331). Thanks @cloyce (Cloyce D. Spradling).
-
Improved compile-time checks of named arguments (#3105, #3214). Thanks @rbrich (Radek Brich).
-
Fixed formatting when both alignment and
0
are given (#3236, #3248). Thanks @ShawnZhong (Shawn Zhong). -
Improved Unicode support in the experimental file API on Windows (#3234, #3293). Thanks @Fros1er (Froster).
-
Unified UTF transcoding (#3416). Thanks @phprus (Vladislav Shchapov).
-
Added support for UTF-8 digit separators via an experimental locale facet (#1861). For example (godbolt):
auto loc = std::locale( std::locale(), new fmt::format_facet<std::locale>("’")); auto s = fmt::format(loc, "{:L}", 1000);
where
’
is U+2019 used as a digit separator in the de_CH locale. -
Added an overload of
formatted_size
that takes a locale (#3084, #3087). Thanks @gerboengels. -
Removed the deprecated
FMT_DEPRECATED_OSTREAM
. -
Fixed a UB when using a null
std::string_view
withfmt::to_string
or format string compilation (#3241, #3244). Thanks @phprus (Vladislav Shchapov). -
Added
starts_with
to the fallbackstring_view
implementation (#3080). Thanks @phprus (Vladislav Shchapov). -
Added
fmt::basic_format_string::get()
for compatibility withbasic_format_string
(#3111). Thanks @huangqinjin. -
Added
println
for compatibility with C++23 (#3267). Thanks @ShawnZhong (Shawn Zhong). -
Renamed the
FMT_EXPORT
macro for shared library usage toFMT_LIB_EXPORT
. -
Improved documentation (#3108, #3169, #3243). #3404). Thanks @Cleroth and @Vertexwahn.
-
Improved build configuration and tests (#3118, #3120, #3188, #3189, #3198, #3205, #3207, #3210, #3240, #3256, #3264, #3299, #3302, #3312, #3317, #3328, #3333, #3369, #3373, #3395, #3406, #3411). Thanks @dimztimz (Dimitrij Mijoski), @phprus (Vladislav Shchapov), @DavidKorczynski, @ChrisThrasher (Chris Thrasher), @FrancoisCarouge (François Carouge), @kennyweiss (Kenny Weiss), @luzpaz, @codeinred (Alecto Irene Perez), @Mixaill (Mikhail Paulyshka), @joycebrum (Joyce), @kevinhwang (Kevin Hwang), @Vertexwahn.
-
Fixed a regression in handling empty format specifiers after a colon (
{:}
) (#3086). Thanks @oxidase (Michael Krasnyk). -
Worked around a broken implementation of
std::is_constant_evaluated
in some versions of libstdc++ on clang (#3247, #3281). Thanks [@phprus (Vladislav Shc...
9.1.0
-
fmt::formatted_size
now works at compile time (#3026). For example (godbolt):#include <fmt/compile.h> int main() { using namespace fmt::literals; constexpr size_t n = fmt::formatted_size("{}"_cf, 42); fmt::print("{}\n", n); // prints 2 }
-
Fixed handling of invalid UTF-8 (#3038, #3044, #3056). Thanks @phprus (Vladislav Shchapov) and @skeeto (Christopher Wellons).
-
Improved Unicode support in
ostream
overloads ofprint
(#2994, #3001, #3025). Thanks @dimztimz (Dimitrij Mijoski). -
Fixed handling of the sign specifier in localized formatting on systems with 32-bit
wchar_t
(#3041). -
Added support for wide streams to
fmt::streamed
(#2994). Thanks @phprus (Vladislav Shchapov). -
Added the
n
specifier that disables the output of delimiters when formatting ranges (#2981, #2983). For example (godbolt):#include <fmt/ranges.h> #include <vector> int main() { auto v = std::vector{1, 2, 3}; fmt::print("{:n}\n", v); // prints 1, 2, 3 }
Thanks @BRevzin (Barry Revzin).
-
Worked around problematic
std::string_view
constructors introduced in C++23 (#3030, #3050). Thanks @strega-nil-ms (nicole mazzuca). -
Improve handling (exclusion) of recursive ranges (#2968, #2974). Thanks @Dani-Hub (Daniel Krügler).
-
Improved error reporting in format string compilation (#3055).
-
Improved the implementation of Dragonbox, the algorithm used for the default floating-point formatting (#2984). Thanks @jk-jeon (Junekey Jeon).
-
Fixed issues with floating-point formatting on exotic platforms.
-
Improved the implementation of chrono formatting (#3010). Thanks @phprus (Vladislav Shchapov).
-
Improved documentation (#2966, #3009, #3020, #3037). Thanks @mwinterb, @jcelerier (Jean-Michaël Celerier) and @remiburtin (Rémi Burtin).
-
Improved build configuration (#2991, #2995, #3004, #3007, #3040). Thanks @dimztimz (Dimitrij Mijoski) and @hwhsu1231 (Haowei Hsu).
-
Fixed various warnings and compilation issues (#2969, #2971, #2975, #2982, #2985, #2988, #3000, #3006, #3014, #3015, #3021, #3023, #3024, #3029, #3043, #3052, #3053, #3054). Thanks @h-friederich (Hannes Friederich), @dimztimz (Dimitrij Mijoski), @olupton (Olli Lupton), @bernhardmgruber (Bernhard Manfred Gruber), @phprus (Vladislav Shchapov).
Pull Requests
- Add xchar support for fmt::streamed(). by @phprus in #2961
- Fixed typo in changelog example by @mwinterb in #2966
- Exclude recursive ranges from the formatter specialization for ranges by @Dani-Hub in #2974
- Pointless comparison warnings by @federico-busato in #2971
- The n specifier for ranges. by @brevzin in #2981
- Fix for EDG frontend (Intel, NVHPC compilers) by @phprus in #2982
- Yet another simplification of Dragonbox by @jk-jeon in #2984
- Add additional search paths for doxygen on Windows by @hwhsu1231 in #2991
- Fixes IBM XLC behavior with uint128 fallback by @federico-busato in #2985
- Reduce filesize of the tests on MinGW by @dimztimz in #2995
- Improve Unicode handling when writing to an ostream on Windows by @dimztimz in #2994
- Add fmt:: namespace to doc by @jcelerier in #3009
- Range formatter by @brevzin in #2983
- Fix Unicode handling for ostream under Windows with libc++. by @dimztimz in #3001
- Improve CI on Windows, deprecate AppVeyor by @dimztimz in #3007
- Simplify and improve chrono formatting by @phprus in #3010
- Suppress unused typedef warning by @h-friederich in #3021
- Remove -Wl,--as-needed linker option by @phprus in #3024
- Use is_utf8() in print(std::ostream&, ...) by @dimztimz in #3025
- Constexpr formatted_size by @marksantaniello in #3026
- Fix testsuite on MinGW + MSVCRT by @dimztimz in #3029
- Fix docs by @remiburtin in #3037
- Prepare for deprecating FindPythonInterp module. by @hwhsu1231 in #3040
- nvhpc/22.3: workaround for c++17 mode by @olupton in #3043
- Fix decoder on broken utf8 sequences. by @phprus in #3044
- Disable non-type template args for nvhpc by @bernhardmgruber in #3053
- Disable bogus -Wstringop-overflow on GCC 11 by @phprus in #3054
- Fix bugs in utf8 decoder by @phprus in #3056
New Contributors
- @hwhsu1231 made their first contribution in #2991
- @dimztimz made their first contribution in #2995
- @h-friederich made their first contribution in #3021
- @marksantaniello made their first contribution in #3026
- @remiburtin made their first contribution in #3037
- @bernhardmgruber made their first contribution in #3053
Full Changelog: 9.0.0...9.1.0
9.0.0
-
Switched to the internal floating point formatter for all decimal presentation formats. In particular this results in consistent rounding on all platforms and removing the
s[n]printf
fallback for decimal FP formatting. -
Compile-time floating point formatting no longer requires the header-only mode. For example (godbolt):
#include <array> #include <fmt/compile.h> consteval auto compile_time_dtoa(double value) -> std::array<char, 10> { auto result = std::array<char, 10>(); fmt::format_to(result.data(), FMT_COMPILE("{}"), value); return result; } constexpr auto answer = compile_time_dtoa(0.42);
works with the default settings.
-
Improved the implementation of Dragonbox, the algorithm used for the default floating-point formatting (#2713, #2750). Thanks @jk-jeon (Junekey Jeon).
-
Made
fmt::to_string
work with__float128
. This uses the internal FP formatter and works even on system without__float128
support in[s]printf
. -
Disabled automatic
std::ostream
insertion operator (operator<<
) discovery whenfmt/ostream.h
is included to prevent ODR violations. You can get the old behavior by definingFMT_DEPRECATED_OSTREAM
but this will be removed in the next major release. Usefmt::streamed
orfmt::ostream_formatter
to enable formatting viastd::ostream
instead. -
Added
fmt::ostream_formatter
that can be used to writeformatter
specializations that perform formatting viastd::ostream
. For example (godbolt):#include <fmt/ostream.h> struct date { int year, month, day; friend std::ostream& operator<<(std::ostream& os, const date& d) { return os << d.year << '-' << d.month << '-' << d.day; } }; template <> struct fmt::formatter<date> : ostream_formatter {}; std::string s = fmt::format("The date is {}", date{2012, 12, 9}); // s == "The date is 2012-12-9"
-
Added the
fmt::streamed
function that takes an object and formats it viastd::ostream
. For example (godbolt):#include <thread> #include <fmt/ostream.h> int main() { fmt::print("Current thread id: {}\n", fmt::streamed(std::this_thread::get_id())); }
Note that
fmt/std.h
provides aformatter
specialization forstd::thread::id
so you don't need to format it viastd::ostream
. -
Deprecated implicit conversions of unscoped enums to integers for consistency with scoped enums.
-
Added an argument-dependent lookup based
format_as
extension API to simplify formatting of enums. -
Added experimental
std::variant
formatting support (#2941). For example (godbolt):#include <variant> #include <fmt/std.h> int main() { auto v = std::variant<int, std::string>(42); fmt::print("{}\n", v); }
prints:
variant(42)
Thanks @jehelset.
-
Added experimental
std::filesystem::path
formatting support (#2865, #2902, #2917, #2918). For example (godbolt):#include <filesystem> #include <fmt/std.h> int main() { fmt::print("There is no place like {}.", std::filesystem::path("/home")); }
prints:
There is no place like "/home".
Thanks @phprus (Vladislav Shchapov).
-
Added a
std::thread::id
formatter tofmt/std.h
. For example (godbolt):#include <thread> #include <fmt/std.h> int main() { fmt::print("Current thread id: {}\n", std::this_thread::get_id()); }
-
Added
fmt::styled
that applies a text style to an individual argument (#2793). For example (godbolt):#include <fmt/chrono.h> #include <fmt/color.h> int main() { auto now = std::chrono::system_clock::now(); fmt::print( "[{}] {}: {}\n", fmt::styled(now, fmt::emphasis::bold), fmt::styled("error", fg(fmt::color::red)), "something went wrong"); }
Thanks @rbrugo (Riccardo Brugo).
-
Made
fmt::print
overload for text styles correctly handle UTF-8 (#2681, #2701). Thanks @AlexGuteniev (Alex Guteniev). -
Fixed Unicode handling when writing to an ostream.
-
Added support for nested specifiers to range formatting (#2673). For example (godbolt):
#include <vector> #include <fmt/ranges.h> int main() { fmt::print("{::#x}\n", std::vector{10, 20, 30}); }
prints
[0xa, 0x14, 0x1e]
.Thanks @BRevzin (Barry Revzin).
-
Implemented escaping of wide strings in ranges (#2904). Thanks @phprus (Vladislav Shchapov).
-
Added support for ranges with
begin
/end
found via the argument-dependent lookup (#2807). Thanks @rbrugo (Riccardo Brugo). -
Fixed formatting of certain kinds of ranges of ranges (#2787). Thanks @BRevzin (Barry Revzin).
-
Fixed handling of maps with element types other than
std::pair
(#2944). Thanks @BrukerJWD (Jonathan W). -
Made tuple formatter enabled only if elements are formattable (#2939, #2940). Thanks @jehelset.
-
Made
fmt::join
compatible with format string compilation (#2719, #2720). Thanks @phprus (Vladislav Shchapov). -
Made compile-time checks work with named arguments of custom types and
std::ostream
print
overloads (#2816, #2817, #2819). Thanks @timsong-cpp. -
Removed
make_args_checked
because it is no longer needed for compile-time checks (#2760). Thanks @phprus (Vladislav Shchapov). -
Removed the following deprecated APIs:
_format
,arg_join
, theformat_to
overload that takes a memory buffer,[v]fprintf
that takes anostream
. -
Removed the deprecated implicit conversion of
[const] signed char*
and[const] unsigned char*
to C strings. -
Removed the deprecated
fmt/locale.h
. -
Replaced the deprecated
fileno()
withdescriptor()
inbuffered_file
. -
Moved
to_string_view
to thedetail
namespace since it's an implementation detail. -
Made access mode of a created file consistent with
fopen
by settingS_IWGRP
andS_IWOTH
(#2733). Thanks @arogge (Andreas Rogge). -
Removed a redundant buffer resize when formatting to
std::ostream
(#2842, #2843). Thanks @jcelerier (Jean-Michaël Celerier). -
Made precision computation for strings consistent with width (#2888).
-
Fixed handling of locale separators in floating point formatting (#2830).
-
Made sign specifiers work with
__int128_t
(#2773). -
Improved support for systems such as CHERI with extra data stored in pointers (#2932). Thanks @davidchisnall (David Chisnall).
-
Improved documentation (#2706, #2712, #2789, #2803, #2805, #2815, #2924). Thanks @BRevzin (Barry Revzin), @Pokechu22, @setoye (Alta), @rtobar, @rbrugo (Riccardo Brugo), @anoonD (cre), @leha-bot (Alex).
-
Improved build configuration (#2766, #2772, #2836, #2852, #2907, #2913, #2914). Thanks @kambala-decapitator (Andrey Filipenkov), @mattiasljungstrom (Mattias Ljungström), @kieselnb (Nick Kiesel), @nathannaveen, @Vertexwahn.
-
Fixed various warnings and compilation issues (#2408, #2507, #2697, #2715, #2717, #2722, #2724, #2725, #2726, #2728, #2732, #2738, #2742, #2744, #2745, #2746, #2754, #2755, #2757, #2758, #2761, #2762, #2763, #2765, #2769, #2770, #2771, #2777, #2779, #2782, #2783, #2794, #2796, #2797, #2801, #2802, #2808, #2818, #2819, #2829, #2835, #2848, #2860, #2861, #2882, #2886, #2891, #2892, #2895, #2896, #2903, #2906, #2908, #2909, #2920, #2922, #2927, #2929, #2936, #2937, #2938, #2951, #2954, #2957, #2958, #2960). Thanks @matrackif @Tobi823 (Tobias Hellmann), @ivan-volnov (Ivan Volnov), @VasiliPupkin256, @federico-busato (Federico), @barcharcraz (Charlie Barto), @jk-jeon (Junekey Jeon), @HazardyKnusperkeks (Björn Schäpers), @dalboris (Boris Dalstein), @seanm (Sean McBride), @gsjaardema (Greg Sjaardema), @timsong-cpp, [@seanm (Sean Mc...