C++ Format v6.0.0 Release Notes
Release Date: 2019-08-26 // over 4 years ago-
Switched to the
MIT license <https://github.com/fmtlib/fmt/blob/5a4b24613ba16cc689977c3b5bd8274a3ba1dd1f/LICENSE.rst>
_ with an optional exception that allows distributing binary code without attribution.0๏ธโฃ Floating-point formatting is now locale-independent by default:
.. code:: c++
#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:.. code:: c++
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:
.. code:: c++
#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
ondtoa-benchmark <https://github.com/fmtlib/dtoa-benchmark>
_ (full results <https://fmt.dev/unknown_mac64_clang10.0.html>
_):.. image:: https://user-images.githubusercontent.com/576385/ 54883977-9fe8c000-4e28-11e9-8bde-272d122e7c52.jpg
๐ Separated formatting and parsing contexts for consistency with
C++20 std::format <http://eel.is/c++draft/format>
_, removing the undocumentedbasic_format_context::parse_context()
function.โ Added
oss-fuzz <https://github.com/google/oss-fuzz>
_ support (#1199 <https://github.com/fmtlib/fmt/pull/1199>
). Thanks@pauldreik (Paul Dreik) <https://github.com/pauldreik>
.formatter
specializations now always take precedence overoperator<<
(#952 <https://github.com/fmtlib/fmt/issues/952>
_):
.. code:: c++
#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 <https://github.com/fmtlib/fmt/issues/618>
,#1169 <https://github.com/fmtlib/fmt/issues/1169>
,#1171 <https://github.com/fmtlib/fmt/pull/1171>
_):
.. code:: c++
#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) <https://github.com/stryku>
_.- โ Added experimental
%
format specifier that formats floating-point values as percentages (#1060 <https://github.com/fmtlib/fmt/pull/1060>
,#1069 <https://github.com/fmtlib/fmt/pull/1069>
,#1071 <https://github.com/fmtlib/fmt/pull/1071>
_):
.. code:: c++
auto s = fmt::format("{:.1%}", 0.42); // s == "42.0%"
Thanks
@gawain-bolton (Gawain Bolton) <https://github.com/gawain-bolton>
_.- Implemented precision for floating-point durations
(
#1004 <https://github.com/fmtlib/fmt/issues/1004>
,#1012 <https://github.com/fmtlib/fmt/pull/1012>
):
.. code:: c++
auto s = fmt::format("{:.1}", std::chrono::duration<double>(1.234)); // s == 1.2s
Thanks
@DanielaE (Daniela Engert) <https://github.com/DanielaE>
_.- Implemented
chrono
format specifiers%Q
and%q
that give the value and the unit respectively (#1019 <https://github.com/fmtlib/fmt/pull/1019>
_):
.. code:: c++
auto value = fmt::format("{:%Q}", 42s); // value == "42" auto unit = fmt::format("{:%q}", 42s); // unit == "s"
Thanks
@DanielaE (Daniela Engert) <https://github.com/DanielaE>
_.- ๐ Fixed handling of dynamic width in chrono formatter:
.. code:: c++
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 <https://github.com/fmtlib/fmt/issues/993>
,#994 <https://github.com/fmtlib/fmt/pull/994>
):
.. code:: c++
#include <fmt/color.h> std::string message = fmt::format(fmt::emphasis::bold | fg(fmt::color::red), "The answer is {}.", 42);
Thanks
@Naios (Denis Blank) <https://github.com/Naios>
_.โ 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 <https://github.com/fmtlib/fmt/pull/1121>
_):
.. code:: c++
std::unique_ptr<int> p = ...; fmt::print("{}", fmt::ptr(p)); // prints p as a pointer
Thanks
@sighingnow (Tao He) <https://github.com/sighingnow>
_.๐จ Made
print
andvprint
report I/O errors (#1098 <https://github.com/fmtlib/fmt/issues/1098>
,#1099 <https://github.com/fmtlib/fmt/pull/1099>
). Thanks@BillyDonahue (Billy Donahue) <https://github.com/BillyDonahue>
_.๐ Marked deprecated APIs with the
[[deprecated]]
attribute and removed internal uses of deprecated APIs (#1022 <https://github.com/fmtlib/fmt/pull/1022>
). Thanks@eliaskosunen (Elias Kosunen) <https://github.com/eliaskosunen>
.โช 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 <https://github.com/fmtlib/fmt/issues/1229>
,#1243 <https://github.com/fmtlib/fmt/pull/1243>
). Thanks@jackoalan (Jack Andersen) <https://github.com/jackoalan>
_.๐ Improved literal-based API (
#1254 <https://github.com/fmtlib/fmt/pull/1254>
). Thanks@sylveon (Charles Milette) <https://github.com/sylveon>
.โ 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 <https://github.com/fmtlib/fmt/issues/1059>
_).โ Added
Sublime Text syntax highlighting config <https://github.com/fmtlib/fmt/blob/master/support/C%2B%2B.sublime-syntax>
_ (#1037 <https://github.com/fmtlib/fmt/issues/1037>
). Thanks@Kronuz (Germรกn Mรฉndez Bravo) <https://github.com/Kronuz>
.Added the
FMT_ENFORCE_COMPILE_STRING
macro to enforce the use of compile-time format strings (#1231 <https://github.com/fmtlib/fmt/pull/1231>
). Thanks@jackoalan (Jack Andersen) <https://github.com/jackoalan>
.๐ Stopped setting
CMAKE_BUILD_TYPE
if {fmt} is a subproject (#1081 <https://github.com/fmtlib/fmt/issues/1081>
_).๐ Various build improvements (
#1039 <https://github.com/fmtlib/fmt/pull/1039>
,#1078 <https://github.com/fmtlib/fmt/pull/1078>
,#1091 <https://github.com/fmtlib/fmt/pull/1091>
,#1103 <https://github.com/fmtlib/fmt/pull/1103>
,#1177 <https://github.com/fmtlib/fmt/pull/1177>
). Thanks@luncliff (Park DongHa) <https://github.com/luncliff>
,@jasonszang (Jason Shuo Zang) <https://github.com/jasonszang>
,@olafhering (Olaf Hering) <https://github.com/olafhering>
,@Lecetem <https://github.com/Lectem>
,@pauldreik (Paul Dreik) <https://github.com/pauldreik>
.๐ Improved documentation (
#1049 <https://github.com/fmtlib/fmt/issues/1049>
,#1051 <https://github.com/fmtlib/fmt/pull/1051>
,#1083 <https://github.com/fmtlib/fmt/pull/1083>
,#1113 <https://github.com/fmtlib/fmt/pull/1113>
,#1114 <https://github.com/fmtlib/fmt/pull/1114>
,#1146 <https://github.com/fmtlib/fmt/issues/1146>
,#1180 <https://github.com/fmtlib/fmt/issues/1180>
,#1250 <https://github.com/fmtlib/fmt/pull/1250>
,#1252 <https://github.com/fmtlib/fmt/pull/1252>
,#1265 <https://github.com/fmtlib/fmt/pull/1265>
). Thanks@mikelui (Michael Lui) <https://github.com/mikelui>
,@foonathan (Jonathan Mรผller) <https://github.com/foonathan>
,@BillyDonahue (Billy Donahue) <https://github.com/BillyDonahue>
,@jwakely (Jonathan Wakely) <https://github.com/jwakely>
,@kaisbe (Kais Ben Salah) <https://github.com/kaisbe>
,@sdebionne (Samuel Debionne) <https://github.com/sdebionne>
.๐ Fixed ambiguous formatter specialization in
fmt/ranges.h
(#1123 <https://github.com/fmtlib/fmt/issues/1123>
_).๐ Fixed formatting of a non-empty
std::filesystem::path
which is an infinitely deep range of its components (#1268 <https://github.com/fmtlib/fmt/issues/1268>
_).๐ Fixed handling of general output iterators when formatting characters (
#1056 <https://github.com/fmtlib/fmt/issues/1056>
,#1058 <https://github.com/fmtlib/fmt/pull/1058>
). Thanks@abolz (Alexander Bolz) <https://github.com/abolz>
_.๐ Fixed handling of output iterators in
formatter
specialization for ranges (#1064 <https://github.com/fmtlib/fmt/issues/1064>
_).๐ Fixed handling of exotic character types (
#1188 <https://github.com/fmtlib/fmt/issues/1188>
_).Made chrono formatting work with exceptions disabled (
#1062 <https://github.com/fmtlib/fmt/issues/1062>
_).๐ Fixed DLL visibility issues (
#1134 <https://github.com/fmtlib/fmt/pull/1134>
,#1147 <https://github.com/fmtlib/fmt/pull/1147>
). Thanks@denchat <https://github.com/denchat>
_.Disabled the use of UDL template extension on GCC 9 (
#1148 <https://github.com/fmtlib/fmt/issues/1148>
_).โ Removed misplaced
format
compile-time checks fromprintf
(#1173 <https://github.com/fmtlib/fmt/issues/1173>
_).๐ Fixed issues in the experimental floating-point formatter (
#1072 <https://github.com/fmtlib/fmt/issues/1072>
,#1129 <https://github.com/fmtlib/fmt/issues/1129>
,#1153 <https://github.com/fmtlib/fmt/issues/1153>
,#1155 <https://github.com/fmtlib/fmt/pull/1155>
,#1210 <https://github.com/fmtlib/fmt/issues/1210>
,#1222 <https://github.com/fmtlib/fmt/issues/1222>
). Thanks@alabuzhev (Alex Alabuzhev) <https://github.com/alabuzhev>
_.๐ Fixed bugs discovered by fuzzing or during fuzzing integration (
#1124 <https://github.com/fmtlib/fmt/issues/1124>
,#1127 <https://github.com/fmtlib/fmt/issues/1127>
,#1132 <https://github.com/fmtlib/fmt/issues/1132>
,#1135 <https://github.com/fmtlib/fmt/pull/1135>
,#1136 <https://github.com/fmtlib/fmt/issues/1136>
,#1141 <https://github.com/fmtlib/fmt/issues/1141>
,#1142 <https://github.com/fmtlib/fmt/issues/1142>
,#1178 <https://github.com/fmtlib/fmt/issues/1178>
,#1179 <https://github.com/fmtlib/fmt/issues/1179>
,#1194 <https://github.com/fmtlib/fmt/issues/1194>
). Thanks@pauldreik (Paul Dreik) <https://github.com/pauldreik>
_.๐ Fixed building tests on FreeBSD and Hurd (
#1043 <https://github.com/fmtlib/fmt/issues/1043>
). Thanks@jackyf (Eugene V. Lyubimkin) <https://github.com/jackyf>
.๐ Fixed various warnings and compilation issues (
#998 <https://github.com/fmtlib/fmt/pull/998>
,#1006 <https://github.com/fmtlib/fmt/pull/1006>
,#1008 <https://github.com/fmtlib/fmt/issues/1008>
,#1011 <https://github.com/fmtlib/fmt/issues/1011>
,#1025 <https://github.com/fmtlib/fmt/issues/1025>
,#1027 <https://github.com/fmtlib/fmt/pull/1027>
,#1028 <https://github.com/fmtlib/fmt/pull/1028>
,#1029 <https://github.com/fmtlib/fmt/pull/1029>
,#1030 <https://github.com/fmtlib/fmt/pull/1030>
,#1031 <https://github.com/fmtlib/fmt/pull/1031>
,#1054 <https://github.com/fmtlib/fmt/pull/1054>
,#1063 <https://github.com/fmtlib/fmt/issues/1063>
,#1068 <https://github.com/fmtlib/fmt/pull/1068>
,#1074 <https://github.com/fmtlib/fmt/pull/1074>
,#1075 <https://github.com/fmtlib/fmt/pull/1075>
,#1079 <https://github.com/fmtlib/fmt/pull/1079>
,#1086 <https://github.com/fmtlib/fmt/pull/1086>
,#1088 <https://github.com/fmtlib/fmt/issues/1088>
,#1089 <https://github.com/fmtlib/fmt/pull/1089>
,#1094 <https://github.com/fmtlib/fmt/pull/1094>
,#1101 <https://github.com/fmtlib/fmt/issues/1101>
,#1102 <https://github.com/fmtlib/fmt/pull/1102>
,#1105 <https://github.com/fmtlib/fmt/issues/1105>
,#1107 <https://github.com/fmtlib/fmt/pull/1107>
,#1115 <https://github.com/fmtlib/fmt/issues/1115>
,#1117 <https://github.com/fmtlib/fmt/issues/1117>
,#1118 <https://github.com/fmtlib/fmt/issues/1118>
,#1120 <https://github.com/fmtlib/fmt/issues/1120>
,#1123 <https://github.com/fmtlib/fmt/issues/1123>
,#1139 <https://github.com/fmtlib/fmt/pull/1139>
,#1140 <https://github.com/fmtlib/fmt/issues/1140>
,#1143 <https://github.com/fmtlib/fmt/issues/1143>
,#1144 <https://github.com/fmtlib/fmt/pull/1144>
,#1150 <https://github.com/fmtlib/fmt/pull/1150>
,#1151 <https://github.com/fmtlib/fmt/pull/1151>
,#1152 <https://github.com/fmtlib/fmt/issues/1152>
,#1154 <https://github.com/fmtlib/fmt/issues/1154>
,#1156 <https://github.com/fmtlib/fmt/issues/1156>
,#1159 <https://github.com/fmtlib/fmt/pull/1159>
,#1175 <https://github.com/fmtlib/fmt/issues/1175>
,#1181 <https://github.com/fmtlib/fmt/issues/1181>
,#1186 <https://github.com/fmtlib/fmt/issues/1186>
,#1187 <https://github.com/fmtlib/fmt/pull/1187>
,#1191 <https://github.com/fmtlib/fmt/pull/1191>
,#1197 <https://github.com/fmtlib/fmt/issues/1197>
,#1200 <https://github.com/fmtlib/fmt/issues/1200>
,#1203 <https://github.com/fmtlib/fmt/issues/1203>
,#1205 <https://github.com/fmtlib/fmt/issues/1205>
,#1206 <https://github.com/fmtlib/fmt/pull/1206>
,#1213 <https://github.com/fmtlib/fmt/issues/1213>
,#1214 <https://github.com/fmtlib/fmt/issues/1214>
,#1217 <https://github.com/fmtlib/fmt/pull/1217>
,#1228 <https://github.com/fmtlib/fmt/issues/1228>
,#1230 <https://github.com/fmtlib/fmt/pull/1230>
,#1232 <https://github.com/fmtlib/fmt/issues/1232>
,#1235 <https://github.com/fmtlib/fmt/pull/1235>
,#1236 <https://github.com/fmtlib/fmt/pull/1236>
,#1240 <https://github.com/fmtlib/fmt/issues/1240>
). Thanks@DanielaE (Daniela Engert) <https://github.com/DanielaE>
,@mwinterb <https://github.com/mwinterb>
,@eliaskosunen (Elias Kosunen) <https://github.com/eliaskosunen>
,@morinmorin <https://github.com/morinmorin>
,@ricco19 (Brian Ricciardelli) <https://github.com/ricco19>
,@waywardmonkeys (Bruce Mitchener) <https://github.com/waywardmonkeys>
,@chronoxor (Ivan Shynkarenka) <https://github.com/chronoxor>
,@remyabel <https://github.com/remyabel>
,@pauldreik (Paul Dreik) <https://github.com/pauldreik>
,@gsjaardema (Greg Sjaardema) <https://github.com/gsjaardema>
,@rcane (Ronny Krรผger) <https://github.com/rcane>
,@mocabe <https://github.com/mocabe>
,@denchat <https://github.com/denchat>
,@cjdb (Christopher Di Bella) <https://github.com/cjdb>
,@HazardyKnusperkeks (Bjรถrn Schรคpers) <https://github.com/HazardyKnusperkeks>
,@vedranmiletic (Vedran Miletiฤ) <https://github.com/vedranmiletic>
,@jackoalan (Jack Andersen) <https://github.com/jackoalan>
,@DaanDeMeyer (Daan De Meyer) <https://github.com/DaanDeMeyer>
,@starkmapper (Mark Stapper) <https://github.com/starkmapper>
_.