C++ Format v6.1.0 Release Notes
Release Date: 2019-12-01 // over 4 years ago-
- β
{fmt} now formats IEEE 754
float
anddouble
using the shortest decimal representation with correct rounding by default:
.. code:: c++
#include <cmath> #include <fmt/core.h> int main() { fmt::print("{}", M_PI); }
prints
3.141592653589793
.- 0οΈβ£ Made the fast binary to decimal floating-point formatter the default,
simplified it and improved performance. {fmt} is now 15 times faster than
libc++'s
std::ostringstream
, 11 times faster thanprintf
and 10% faster than double-conversion ondtoa-benchmark <https://github.com/fmtlib/dtoa-benchmark>
_:
================== ========= ======= Function Time (ns) Speedup ================== ========= ======= ostringstream 1,346.30 1.00x ostrstream 1,195.74 1.13x sprintf 995.08 1.35x doubleconv 99.10 13.59x fmt 88.34 15.24x ================== ========= =======
.. image:: https://user-images.githubusercontent.com/576385/ 69767160-cdaca400-112f-11ea-9fc5-347c9f83caad.png
- {fmt} no longer converts
float
arguments todouble
. In particular this improves the default (shortest) representation of floats and makesfmt::format
consistent withstd::format
specs (#1336 <https://github.com/fmtlib/fmt/issues/1336>
,#1353 <https://github.com/fmtlib/fmt/issues/1353>
,#1360 <https://github.com/fmtlib/fmt/pull/1360>
,#1361 <https://github.com/fmtlib/fmt/pull/1361>
):
.. code:: c++
fmt::print("{}", 0.1f);
prints
0.1
instead of0.10000000149011612
.Thanks
@orivej (Orivej Desh) <https://github.com/orivej>
_.π¨ Made floating-point formatting output consistent with
printf
/iostreams (#1376 <https://github.com/fmtlib/fmt/issues/1376>
,#1417 <https://github.com/fmtlib/fmt/issues/1417>
).β Added support for 128-bit integers (
#1287 <https://github.com/fmtlib/fmt/pull/1287>
_):
.. code:: c++
fmt::print("{}", std::numeric_limits<__int128_t>::max());
prints
170141183460469231731687303715884105727
.Thanks
@denizevrenci (Deniz Evrenci) <https://github.com/denizevrenci>
_.π The overload of
print
that takestext_style
is now atomic, i.e. the output from different threads doesn't interleave (#1351 <https://github.com/fmtlib/fmt/pull/1351>
). Thanks@tankiJong (Tanki Zhang) <https://github.com/tankiJong>
.Made compile time in the header-only mode ~20% faster by reducing the number of template instantiations.
wchar_t
overload ofvprint
was moved fromfmt/core.h
tofmt/format.h
.β Added an overload of
fmt::join
that works with tuples (#1322 <https://github.com/fmtlib/fmt/issues/1322>
,#1330 <https://github.com/fmtlib/fmt/pull/1330>
):
.. code:: c++
#include <tuple> #include <fmt/ranges.h> int main() { std::tuple<char, int, float> t{'a', 1, 2.0f}; fmt::print("{}", t); }
prints
('a', 1, 2.0)
.Thanks
@jeremyong (Jeremy Ong) <https://github.com/jeremyong>
_.- π Changed formatting of octal zero with prefix from "00" to "0":
.. code:: c++
fmt::print("{:#o}", 0);
prints
0
.- The locale is now passed to ostream insertion (
<<
) operators (#1406 <https://github.com/fmtlib/fmt/pull/1406>
_):
.. code:: c++
#include <fmt/locale.h> #include <fmt/ostream.h> struct S { double value; }; std::ostream& operator<<(std::ostream& os, S s) { return os << s.value; } int main() { auto s = fmt::format(std::locale("fr_FR.UTF-8"), "{}", S{0.42}); // s == "0,42" }
Thanks
@dlaugt (Daniel LaΓΌgt) <https://github.com/dlaugt>
_.Locale-specific number formatting now uses grouping (
#1393 <https://github.com/fmtlib/fmt/issues/1393>
_#1394 <https://github.com/fmtlib/fmt/pull/1394>
). Thanks@skrdaniel <https://github.com/skrdaniel>
.π Fixed handling of types with deleted implicit rvalue conversion to
const char**
(#1421 <https://github.com/fmtlib/fmt/issues/1421>
_):
.. code:: c++
struct mystring { operator const char*() const&; operator const char*() &; operator const char*() const&& = delete; operator const char*() && = delete; }; mystring str; fmt::print("{}", str); // now compiles
Enums are now mapped to correct underlying types instead of
int
(#1286 <https://github.com/fmtlib/fmt/pull/1286>
). Thanks@agmt (Egor Seredin) <https://github.com/agmt>
.Enum classes are no longer implicitly converted to
int
(#1424 <https://github.com/fmtlib/fmt/issues/1424>
_).Added
basic_format_parse_context
for consistency with C++20std::format
and deprecatedbasic_parse_context
.π Fixed handling of UTF-8 in precision (
#1389 <https://github.com/fmtlib/fmt/issues/1389>
,#1390 <https://github.com/fmtlib/fmt/pull/1390>
). Thanks@tajtiattila (Attila Tajti) <https://github.com/tajtiattila>
_.π {fmt} can now be installed on Linux, macOS and Windows with
Conda <https://docs.conda.io/en/latest/>
__ using itsconda-forge <https://conda-forge.org>
__package <https://github.com/conda-forge/fmt-feedstock>
__ (#1410 <https://github.com/fmtlib/fmt/pull/1410>
_)::conda install -c conda-forge fmt
Thanks
@tdegeus (Tom de Geus) <https://github.com/tdegeus>
_.β Added a CUDA test (
#1285 <https://github.com/fmtlib/fmt/pull/1285>
,#1317 <https://github.com/fmtlib/fmt/pull/1317>
). Thanks@luncliff (Park DongHa) <https://github.com/luncliff>
_ and@risa2000 <https://github.com/risa2000>
_.π Improved documentation (
#1276 <https://github.com/fmtlib/fmt/pull/1276>
,#1291 <https://github.com/fmtlib/fmt/issues/1291>
,#1296 <https://github.com/fmtlib/fmt/issues/1296>
,#1315 <https://github.com/fmtlib/fmt/pull/1315>
,#1332 <https://github.com/fmtlib/fmt/pull/1332>
,#1337 <https://github.com/fmtlib/fmt/pull/1337>
,#1395 <https://github.com/fmtlib/fmt/issues/1395>
_#1418 <https://github.com/fmtlib/fmt/pull/1418>
). Thanks@waywardmonkeys (Bruce Mitchener) <https://github.com/waywardmonkeys>
,@pauldreik (Paul Dreik) <https://github.com/pauldreik>
,@jackoalan (Jack Andersen) <https://github.com/jackoalan>
.Various code improvements (
#1358 <https://github.com/fmtlib/fmt/pull/1358>
,#1407 <https://github.com/fmtlib/fmt/pull/1407>
). Thanks@orivej (Orivej Desh) <https://github.com/orivej>
,@dpacbach (David P. Sicilia) <https://github.com/dpacbach>
,π Fixed compile-time format string checks for user-defined types (
#1292 <https://github.com/fmtlib/fmt/issues/1292>
_).Worked around a false positive in
unsigned-integer-overflow
sanitizer (#1377 <https://github.com/fmtlib/fmt/issues/1377>
_).π Fixed various warnings and compilation issues (
#1273 <https://github.com/fmtlib/fmt/issues/1273>
,#1278 <https://github.com/fmtlib/fmt/pull/1278>
,#1280 <https://github.com/fmtlib/fmt/pull/1280>
,#1281 <https://github.com/fmtlib/fmt/issues/1281>
,#1288 <https://github.com/fmtlib/fmt/issues/1288>
,#1290 <https://github.com/fmtlib/fmt/pull/1290>
,#1301 <https://github.com/fmtlib/fmt/pull/1301>
,#1305 <https://github.com/fmtlib/fmt/issues/1305>
,#1306 <https://github.com/fmtlib/fmt/issues/1306>
,#1309 <https://github.com/fmtlib/fmt/issues/1309>
,#1312 <https://github.com/fmtlib/fmt/pull/1312>
,#1313 <https://github.com/fmtlib/fmt/issues/1313>
,#1316 <https://github.com/fmtlib/fmt/issues/1316>
,#1319 <https://github.com/fmtlib/fmt/issues/1319>
,#1320 <https://github.com/fmtlib/fmt/pull/1320>
,#1326 <https://github.com/fmtlib/fmt/pull/1326>
,#1328 <https://github.com/fmtlib/fmt/pull/1328>
,#1344 <https://github.com/fmtlib/fmt/issues/1344>
,#1345 <https://github.com/fmtlib/fmt/pull/1345>
,#1347 <https://github.com/fmtlib/fmt/pull/1347>
,#1349 <https://github.com/fmtlib/fmt/pull/1349>
,#1354 <https://github.com/fmtlib/fmt/issues/1354>
,#1362 <https://github.com/fmtlib/fmt/issues/1362>
,#1366 <https://github.com/fmtlib/fmt/issues/1366>
,#1364 <https://github.com/fmtlib/fmt/pull/1364>
,#1370 <https://github.com/fmtlib/fmt/pull/1370>
,#1371 <https://github.com/fmtlib/fmt/pull/1371>
,#1385 <https://github.com/fmtlib/fmt/issues/1385>
,#1388 <https://github.com/fmtlib/fmt/issues/1388>
,#1397 <https://github.com/fmtlib/fmt/pull/1397>
,#1414 <https://github.com/fmtlib/fmt/pull/1414>
,#1416 <https://github.com/fmtlib/fmt/pull/1416>
,#1422 <https://github.com/fmtlib/fmt/issues/1422>
_#1427 <https://github.com/fmtlib/fmt/pull/1427>
,#1431 <https://github.com/fmtlib/fmt/issues/1431>
,#1433 <https://github.com/fmtlib/fmt/pull/1433>
). Thanks@hhb <https://github.com/hhb>
,@gsjaardema (Greg Sjaardema) <https://github.com/gsjaardema>
,@gabime (Gabi Melman) <https://github.com/gabime>
,@neheb (Rosen Penev) <https://github.com/neheb>
,@vedranmiletic (Vedran MiletiΔ) <https://github.com/vedranmiletic>
,@dkavolis (Daumantas Kavolis) <https://github.com/dkavolis>
,@mwinterb <https://github.com/mwinterb>
,@orivej (Orivej Desh) <https://github.com/orivej>
,@denizevrenci (Deniz Evrenci) <https://github.com/denizevrenci>
@leonklingele <https://github.com/leonklingele>
,@chronoxor (Ivan Shynkarenka) <https://github.com/chronoxor>
,@kent-tri <https://github.com/kent-tri>
,@0x8000-0000 (Florin Iucha) <https://github.com/0x8000-0000>
,@marti4d (Chris Martin) <https://github.com/marti4d>
_.
- β
{fmt} now formats IEEE 754