diff --git a/ChangeLog.rst b/ChangeLog.rst index 03cb8213..5fa7b9c5 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,11 +1,58 @@ 5.0.0 - TBD ----------- -* Added a requirement for compiler support for variadic templates and dropped ``FMT_VARIADIC_*`` emulation macros. Variadic templates are available since GCC 4.4, Clang 2.9 and MSVC 18.0 (2013). For older compilers use `version 4.x `_ which continues to be maintained. +* Added a requirement for compiler support for variadic templates and dropped + ``FMT_VARIADIC_*`` emulation macros. Variadic templates are available since + GCC 4.4, Clang 2.9 and MSVC 18.0 (2013). For older compilers use `version 4.x + `_ which continues to be + maintained. -* Renamed symbols to follow standard C++ naming conventions and cleaned the argument handling API: ``ArgList`` -> ``format_args``, ``ArgArray`` -> ``format_arg_store``, etc. +* Renamed symbols to follow standard C++ naming conventions and proposed a subset + of the library for standardization in `P0645R2 Text Formatting + `_. -* Added the `make_format_args `_ function for capturing formatting arguments: +* Swparated format string parsing and formatting in the extension API to enable + compile-time format-string processing. For example + + .. code:: c++ + + struct S {}; + + namespace fmt { + template <> + struct formatter { + constexpr auto parse(parse_context& ctx) { + auto it = ctx.begin(); + spec = *it; + if (spec != 'd' && spec != 's') + throw format_error("invalid specifier"); + ++it; + return it; + } + + template + auto format(S, FormatContext& ctx) { + return spec == 's' ? + format_to(ctx.begin(), "{}", "fourty-two") : + format_to(ctx.begin(), "{}", 42); + } + + char spec = 0; + }; + } + + std::string s = fmt::format(fmt("{:x}"), S()); + + will give a compile-time error due to invalid format specifier (`godbolt + `_):: + + ... + :12:45: error: expression '' is not a constant expression + throw format_error("invalid specifier"); + +* Added the `make_format_args + `_ + function for capturing formatting arguments: .. code:: c++ @@ -19,7 +66,8 @@ vreport_error(format, fmt::make_format_args(args...)); } -* Added prefix ``v`` to non-variadic functions taking ``format_args`` to distinguish them from variadic ones: +* Added prefix ``v`` to non-variadic functions taking ``format_args`` to + distinguish them from variadic ones: .. code:: c++ @@ -28,21 +76,110 @@ template std::string format(string_view format_str, const Args & ... args); -* Added a section on `formatting user-defined `_ types to the docs (`#393 `_). Thanks `@pwm1234 (Phil) `_. +* Switched from a custom null-terminated string view class to ``string_view`` + in the format API and provided ``fmt::string_view`` which implements a subset + of ``std::string_view`` API for pre-C++17 systems. -* Fixed compilation on Android (`#381 `_). - Thanks `@hghwng (Hugh Wang) `_. +* Removed the write API in favor of the `format API + `_ with compile-time handling of + format strings. -* Fixed Linux compilation with ``-fno-exceptions`` (`#402 `_). - Thanks `@JanHellwig (Jan Hellwig) `_. +* Added a section on `formatting user-defined types + `_ to the docs + (`#393 `_). + Thanks `@pwm1234 (Phil) `_. -* Implemented thread-safe time formatting (`#395 `_, `#396 `_). +* Added a section describing `the use of header-only target with CMake + `_ to the docs + (`#515 `_). + Thanks `@ibell (Ian Bell) `_. + +* Implemented thread-safe time formatting ( + `#395 `_, + `#396 `_). Thanks `@codicodi `_. -* Removed unnecessary ``fmt/`` prefix in includes (`#397 `_). +* Implemented more efficient handling of large number of format arguments. + +* Added a version macro ``FMT_VERSION`` + (`#411 `_). + +* Removed unnecessary ``fmt/`` prefix in includes + (`#397 `_). Thanks `@chronoxor (Ivan Shynkarenka) `_. -* Renamed ``CHAR_WIDTH`` to ``CHAR_SIZE`` to avoid collision with ISO/IEC TS 18661-1:2014 macro. +* Renamed ``CHAR_WIDTH`` to ``CHAR_SIZE`` to avoid collision with ISO/IEC TS + 18661-1:2014 macro. + +* Replaced literal 0 with ``nullptr`` in pointer contexts + (`#409 `_). + Thanks `@alabuzhev (Alex Alabuzhev) `_. + +* Added ``std::basic_string`` allocator support to ``fmt::string_view`` + (`#441 `_). + Thanks `@glebov-andrey (Andrey Glebov) `_. + +* Stopped exporting the ``-std=c++11`` flag from the ``fmt`` target + (`#445 `_). + Thanks `@EricWF (Eric) `_. + +* Made ``%s`` a generic format specifier that works with any argument type in + ``fmt::printf`` (`#453 `_). + Thanks `@mojoBrendan `_: + + .. code:: c++ + + fmt::printf("%s", 42); + +* Placed CMake imported targets in the `fmt` namespace ( + `#511 `_, + `#513 `_). + Thanks `@bjoernthiel (Bjoern Thiel) `_ and + `@niosHD (Mario Werner) `_. + +* Fixed minimal supported library subset ( + `#418 `_, + `#419 `_, + `#420 `_). + Thanks `@alabuzhev (Alex Alabuzhev) `_. + +* Fixed compilation on Android + (`#381 `_). + Thanks `@hghwng (Hugh Wang) `_. + +* Fixed compilation with ``-fno-exceptions`` ( + `#402 `_, + `#405 `_). + Thanks `@JanHellwig (Jan Hellwig) `_. + +* Fixed compilation as a shared library with Clang + (`#413 `_). + Thanks `@foonathan (Jonathan Müller) `_. + +* Fixed test compilation on FreeBSD + (`#433 `_). + Thanks `@WscriChy `_. + +* Fixed a name conflict with Xlib + (`#483 `_). + +* Fixed signbit detection (`#423 `_). + +* Fixed missing intrinsic when included from C++/CLI + (`#457 `_). + Thanks `@calumr (Calum Robinson) `_. + +* Fixed Android not being detected with NDK 13b toolchain + (`#458 `_). + Thanks `@Gachapen (Magnus Bjerke Vik) `_. + +* Added ``SOURCELINK_SUFFIX`` for compatibility with Sphinx 1.5 + (`#497 `_). + Thanks `@ginggs (Graham Inggs) `_. + +* Added ``FMT_API`` declarations where needed for building a DLL + (`#469 `_). + Thanks `@richardeakin (Richard Eakin) `_. 4.1.0 - 2017-12-20 ------------------ @@ -293,6 +430,9 @@ `@chenhayat (Chen Hayat) `_ and `@trozen `_. +* Worked around a broken ``__builtin_clz`` in clang with MS codegen + (`#519 `_). + * Removed redundant include (`#479 `_). diff --git a/doc/api.rst b/doc/api.rst index 9372743f..b65a8fc6 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -49,8 +49,6 @@ arguments in the resulting string. .. doxygenfunction:: print(std::FILE *, string_view, const Args&...) .. doxygenfunction:: vprint(std::FILE *, string_view, format_args) -.. _format-api: - Named arguments --------------- @@ -81,6 +79,8 @@ Compatibility .. doxygentypedef:: fmt::string_view .. doxygentypedef:: fmt::wstring_view +.. _format-api: + Format API ========== @@ -153,6 +153,8 @@ Utilities .. doxygenfunction:: fmt::to_string(const T&) +.. doxygenfunction:: fmt::to_wstring(const T&) + .. doxygenclass:: fmt::basic_memory_buffer :protected-members: :members: diff --git a/doc/index.rst b/doc/index.rst index b7b2fa86..fa5701a4 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -16,7 +16,7 @@ alternative to C++ IOStreams. -.. _format-api: +.. _format-api-intro: Format API ---------- diff --git a/doc/usage.rst b/doc/usage.rst index ed0c3e2d..4d39882c 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -67,6 +67,7 @@ your ``CMakeLists.txt`` file:: add_subdirectory(fmt) or + :: add_subdirectory(fmt EXCLUDE_FROM_ALL) diff --git a/include/fmt/core.h b/include/fmt/core.h index 8580cc93..66597eed 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -134,7 +134,8 @@ #endif #ifndef FMT_BEGIN_NAMESPACE -# if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_MSC_VER >= 1900 +# if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_GCC_VERSION >= 404 || \ + FMT_MSC_VER >= 1900 # define FMT_INLINE_NAMESPACE inline namespace # define FMT_END_NAMESPACE }} # else diff --git a/include/fmt/format.h b/include/fmt/format.h index a513c4ab..07c644aa 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3390,6 +3390,11 @@ std::string to_string(const T &value) { return str; } +/** + \rst + Converts *value* to ``std::wstring`` using the default format for type *T*. + \endrst + */ template std::wstring to_wstring(const T &value) { std::wstring str;