6.0.0
版本发布时间: 2019-08-26 21:59:18
fmtlib/fmt最新发布版本:11.0.2(2024-07-20 22:32:04)
-
Switched to the MIT license with an optional exception that allows distributing binary code without attribution.
-
Floating-point formatting is now locale-independent by default:
#include <locale> #include <fmt/core.h> int main() { std::locale::global(std::locale("ru_RU.UTF-8")); fmt::print("value = {}", 4.2); }
prints "value = 4.2" regardless of the locale. For locale-specific formatting use the
n
specifier:std::locale::global(std::locale("ru_RU.UTF-8")); fmt::print("value = {:n}", 4.2);
prints "value = 4,2".
-
Added an experimental Grisu floating-point formatting algorithm implementation (disabled by default). To enable it compile with the
FMT_USE_GRISU
macro defined to 1:#define FMT_USE_GRISU 1 #include <fmt/format.h> auto s = fmt::format("{}", 4.2); // formats 4.2 using Grisu
With Grisu enabled, {fmt} is 13x faster than
std::ostringstream
(libc++) and 10x faster thansprintf
on dtoa-benchmark (full results): -
Separated formatting and parsing contexts for consistency with C++20 std::format, removing the undocumented
basic_format_context::parse_context()
function. -
Added oss-fuzz support (#1199). Thanks @pauldreik (Paul Dreik).
-
formatter
specializations now always take precedence overoperator<<
(#952):#include <iostream> #include <fmt/ostream.h> struct S {}; std::ostream& operator<<(std::ostream& os, S) { return os << 1; } template <> struct fmt::formatter<S> : fmt::formatter<int> { auto format(S, format_context& ctx) { return formatter<int>::format(2, ctx); } }; int main() { std::cout << S() << "\n"; // prints 1 using operator<< fmt::print("{}\n", S()); // prints 2 using formatter }
-
Introduced the experimental
fmt::compile
function that does format string compilation (#618, #1169, #1171):#include <fmt/compile.h> auto f = fmt::compile<int>("{}"); std::string s = fmt::format(f, 42); // can be called multiple times to format // different values // s == "42"
It moves the cost of parsing a format string outside of the format function which can be beneficial when identically formatting many objects of the same types. Thanks @stryku (Mateusz Janek).
-
Added experimental support for the
%
format specifier that formats floating-point values as percentages (#1060, #1069, #1071):auto s = fmt::format("{:.1%}", 0.42); // s == "42.0%"
Thanks @gawain-bolton (Gawain Bolton).
-
Implemented precision for floating-point durations (#1004, #1012):
auto s = fmt::format("{:.1}", std::chrono::duration<double>(1.234)); // s == 1.2s
Thanks @DanielaE (Daniela Engert).
-
Implemented
chrono
format specifiers%Q
and%q
that give the value and the unit respectively (#1019):auto value = fmt::format("{:%Q}", 42s); // value == "42" auto unit = fmt::format("{:%q}", 42s); // unit == "s"
Thanks @DanielaE (Daniela Engert).
-
Fixed handling of dynamic width in chrono formatter:
auto s = fmt::format("{0:{1}%H:%M:%S}", std::chrono::seconds(12345), 12); // ^ width argument index ^ width // s == "03:25:45 "
Thanks Howard Hinnant.
-
Removed deprecated
fmt/time.h
. Usefmt/chrono.h
instead. -
Added
fmt::format
andfmt::vformat
overloads that taketext_style
(#993, #994):#include <fmt/color.h> std::string message = fmt::format(fmt::emphasis::bold | fg(fmt::color::red), "The answer is {}.", 42);
Thanks @Naios (Denis Blank).
-
Removed the deprecated color API (
print_colored
). Use the new API, namelyprint
overloads that taketext_style
instead. -
Made
std::unique_ptr
andstd::shared_ptr
formattable as pointers viafmt::ptr
(#1121):std::unique_ptr<int> p = ...; fmt::print("{}", fmt::ptr(p)); // prints p as a pointer
Thanks @sighingnow (Tao He).
-
Made
print
andvprint
report I/O errors (#1098, #1099). Thanks @BillyDonahue (Billy Donahue). -
Marked deprecated APIs with the
[[deprecated]]
attribute and removed internal uses of deprecated APIs (#1022). Thanks @eliaskosunen (Elias Kosunen). -
Modernized the codebase using more C++11 features and removing workarounds. Most importantly,
buffer_context
is now an alias template, so usebuffer_context<T>
instead ofbuffer_context<T>::type
. These features require GCC 4.8 or later. -
formatter
specializations now always take precedence over implicit conversions toint
and the undocumentedconvert_to_int
trait is now deprecated. -
Moved the undocumented
basic_writer
,writer
, andwwriter
types to theinternal
namespace. -
Removed deprecated
basic_format_context::begin()
. Useout()
instead. -
Disallowed passing the result of
join
as an lvalue to prevent misuse. -
Refactored the undocumented structs that represent parsed format specifiers to simplify the API and allow multibyte fill.
-
Moved SFINAE to template parameters to reduce symbol sizes.
-
Switched to
fputws
for writing wide strings so that it's no longer required to call_setmode
on Windows (#1229, #1243). Thanks @jackoalan (Jack Andersen). -
Improved literal-based API (#1254). Thanks @sylveon (Charles Milette).
-
Added support for exotic platforms without
uintptr_t
such as IBM i (AS/400) which has 128-bit pointers and only 64-bit integers (#1059). -
Added Sublime Text syntax highlighting config (#1037). Thanks @Kronuz (Germán Méndez Bravo).
-
Added the
FMT_ENFORCE_COMPILE_STRING
macro to enforce the use of compile-time format strings (#1231). Thanks @jackoalan (Jack Andersen). -
Stopped setting
CMAKE_BUILD_TYPE
if {fmt} is a subproject (#1081). -
Various build improvements (#1039, #1078, #1091, #1103, #1177). Thanks @luncliff (Park DongHa), @jasonszang (Jason Shuo Zang), @olafhering (Olaf Hering), @Lecetem, @pauldreik (Paul Dreik).
-
Improved documentation (#1049, #1051, #1083, #1113, #1114, #1146, #1180, #1250, #1252, #1265). Thanks @mikelui (Michael Lui), @foonathan (Jonathan Müller), @BillyDonahue (Billy Donahue), @jwakely (Jonathan Wakely), @kaisbe (Kais Ben Salah), @sdebionne (Samuel Debionne).
-
Fixed ambiguous formatter specialization in
fmt/ranges.h
(#1123). -
Fixed formatting of a non-empty
std::filesystem::path
which is an infinitely deep range of its components (#1268). -
Fixed handling of general output iterators when formatting characters (#1056, #1058). Thanks @abolz (Alexander Bolz).
-
Fixed handling of output iterators in
formatter
specialization for ranges (#1064). -
Fixed handling of exotic character types (#1188).
-
Made chrono formatting work with exceptions disabled (#1062).
-
Fixed DLL visibility issues (#1134, #1147). Thanks @denchat.
-
Disabled the use of UDL template extension on GCC 9 (#1148).
-
Removed misplaced
format
compile-time checks fromprintf
(#1173). -
Fixed issues in the experimental floating-point formatter (#1072, #1129, #1153, #1155, #1210, #1222). Thanks @alabuzhev (Alex Alabuzhev).
-
Fixed bugs discovered by fuzzing or during fuzzing integration (#1124, #1127, #1132, #1135, #1136, #1141, #1142, #1178, #1179, #1194). Thanks @pauldreik (Paul Dreik).
-
Fixed building tests on FreeBSD and Hurd (#1043). Thanks @jackyf (Eugene V. Lyubimkin).
-
Fixed various warnings and compilation issues (#998, #1006, #1008, #1011, #1025, #1027, #1028, #1029, #1030, #1031, #1054, #1063, #1068, #1074, #1075, #1079, #1086, #1088, #1089, #1094, #1101, #1102, #1105, #1107, #1115, #1117, #1118, #1120, #1123, #1139, #1140, #1143, #1144, #1150, #1151, #1152, #1154, #1156, #1159, #1175, #1181, #1186, #1187, #1191, #1197, #1200, #1203, #1205, #1206, #1213, #1214, #1217, #1228, #1230, #1232, #1235, #1236, #1240). Thanks @DanielaE (Daniela Engert), @mwinterb, @eliaskosunen (Elias Kosunen), @morinmorin, @ricco19 (Brian Ricciardelli), @waywardmonkeys (Bruce Mitchener), @chronoxor (Ivan Shynkarenka), @remyabel, @pauldreik (Paul Dreik), @gsjaardema (Greg Sjaardema), @rcane (Ronny Krüger), @mocabe, @denchat, @cjdb (Christopher Di Bella), @HazardyKnusperkeks (Björn Schäpers), @vedranmiletic (Vedran Miletić), @jackoalan (Jack Andersen), @DaanDeMeyer (Daan De Meyer), @starkmapper (Mark Stapper).
1、 fmt-6.0.0.zip 1.07MB