diff --git a/doc/api.rst b/doc/api.rst index 355ecfdb..0c3a54d3 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -183,7 +183,7 @@ output ``operator<<`` when one is defined for a user-defined type. Output iterator support ----------------------- -.. doxygenfunction:: fmt::format_to(OutputIt, const String&, const Args&...) +.. doxygenfunction:: fmt::format_to(OutputIt, const S&, const Args&...) .. doxygenfunction:: fmt::format_to_n(OutputIt, std::size_t, string_view, const Args&...) .. doxygenstruct:: fmt::format_to_n_result :members: @@ -200,6 +200,8 @@ The following user-defined literals are defined in ``fmt/format.h``. Utilities --------- +.. doxygentypedef:: fmt::char_t + .. doxygenfunction:: fmt::formatted_size(string_view, const Args&...) .. doxygenfunction:: fmt::to_string(const T&) diff --git a/doc/build.py b/doc/build.py index e95175f5..e44ad7c3 100755 --- a/doc/build.py +++ b/doc/build.py @@ -89,11 +89,11 @@ def build_docs(version='dev', **kwargs): FMT_USE_VARIADIC_TEMPLATES=1 \ FMT_USE_RVALUE_REFERENCES=1 \ FMT_USE_USER_DEFINED_LITERALS=1 \ + FMT_USE_ALIAS_TEMPLATES=1 \ FMT_API= \ "FMT_BEGIN_NAMESPACE=namespace fmt {{" \ "FMT_END_NAMESPACE=}}" \ - "FMT_STRING_ALIAS=1" \ - "FMT_CHAR(S)=char_t" + "FMT_STRING_ALIAS=1" EXCLUDE_SYMBOLS = fmt::internal::* StringValue write_str '''.format(include_dir, doxyxml_dir).encode('UTF-8')) if p.returncode != 0: diff --git a/include/fmt/color.h b/include/fmt/color.h index a1ee3b03..f5826bde 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -296,7 +296,7 @@ void vprint_rgb(rgb fd, rgb bg, const String &format, fmt::print(fmt::color::red, "Elapsed time: {0:.2f} seconds", 1.23); */ template -typename std::enable_if::value>::type +typename std::enable_if::value>::type print(rgb fd, const String &format_str, const Args & ... args) { internal::check_format_string(format_str); typedef typename internal::format_string_traits::char_type char_t; @@ -313,7 +313,7 @@ print(rgb fd, const String &format_str, const Args & ... args) { "Elapsed time: {0:.2f} seconds", 1.23); */ template -typename std::enable_if::value>::type +typename std::enable_if::value>::type print(rgb fd, rgb bg, const String &format_str, const Args & ... args) { internal::check_format_string(format_str); typedef typename internal::format_string_traits::char_type char_t; diff --git a/include/fmt/core.h b/include/fmt/core.h index 32647c1b..c6c44e53 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -500,7 +500,7 @@ struct format_string_traits< format_string_traits_base {}; template -struct is_format_string : std::is_empty> {}; +struct is_string : std::is_empty> {}; template struct is_compile_string : std::is_base_of {}; @@ -1233,7 +1233,7 @@ class basic_format_args { /** An alias to ``basic_format_args``. */ // It is a separate type rather than a typedef to make symbols readable. -struct format_args: basic_format_args { +struct format_args : basic_format_args { template format_args(Args &&... arg) : basic_format_args(std::forward(arg)...) {} @@ -1244,12 +1244,23 @@ struct wformat_args : basic_format_args { : basic_format_args(std::forward(arg)...) {} }; -#if FMT_HAS_FEATURE(cxx_alias_templates) +#ifndef FMT_USE_ALIAS_TEMPLATES +# define FMT_USE_ALIAS_TEMPLATES FMT_HAS_FEATURE(cxx_alias_templates) +#endif +#if FMT_USE_ALIAS_TEMPLATES +/** String's character type. */ template using char_t = typename internal::format_string_traits::char_type; #define FMT_CHAR(S) char_t + +template +using enable_if_string_t = + typename std::enable_if::value, T>::type; +#define FMT_ENABLE_IF_STRING(S, T) enable_if_string_t #else #define FMT_CHAR(S) typename internal::format_string_traits::char_type +#define FMT_ENABLE_IF_STRING(S, T) \ + typename std::enable_if::value, T>::type #endif namespace internal { @@ -1258,7 +1269,8 @@ struct named_arg_base { basic_string_view name; // Serialized value. - mutable char data[sizeof(basic_format_arg::type>)]; + mutable char data[ + sizeof(basic_format_arg::type>)]; named_arg_base(basic_string_view nm) : name(nm) {} @@ -1362,7 +1374,7 @@ typename std::enable_if< template inline typename std::enable_if< - is_contiguous::value && internal::is_format_string::value, + is_contiguous::value && internal::is_string::value, std::back_insert_iterator>::type format_to(std::back_insert_iterator out, const S &format_str, const Args &... args) { @@ -1410,7 +1422,7 @@ FMT_API void vprint(std::FILE *f, wstring_view format_str, wformat_args args); \endrst */ template -inline typename std::enable_if::value>::type +inline FMT_ENABLE_IF_STRING(S, void) print(std::FILE *f, const S &format_str, const Args &... args) { vprint(f, internal::to_string_view(format_str), internal::checked_args(format_str, args...)); @@ -1429,7 +1441,7 @@ FMT_API void vprint(wstring_view format_str, wformat_args args); \endrst */ template -inline typename std::enable_if::value>::type +inline FMT_ENABLE_IF_STRING(S, void) print(const S &format_str, const Args &... args) { vprint(internal::to_string_view(format_str), internal::checked_args(format_str, args...)); diff --git a/include/fmt/format.h b/include/fmt/format.h index 7c3d5719..49abeb03 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3530,14 +3530,13 @@ inline OutputIt vformat_to( fmt::format_to(std::back_inserter(out), "{}", 42); \endrst */ -template -inline typename std::enable_if< - internal::is_format_string::value, OutputIt>::type - format_to(OutputIt out, const String &format_str, const Args &... args) { +template +inline FMT_ENABLE_IF_STRING(S, OutputIt) + format_to(OutputIt out, const S &format_str, const Args &... args) { internal::check_format_string(format_str); - typedef typename format_context_t::type context; + typedef typename format_context_t::type context; format_arg_store as{args...}; - return vformat_to(out, basic_string_view(format_str), + return vformat_to(out, basic_string_view(format_str), basic_format_args(as)); } @@ -3580,15 +3579,13 @@ inline format_to_n_result vformat_to_n( end of the output range. \endrst */ -template -inline typename std::enable_if< - internal::is_format_string::value, - format_to_n_result>::type format_to_n( - OutputIt out, std::size_t n, const String &format_str, - const Args &... args) { +template +inline FMT_ENABLE_IF_STRING(S, format_to_n_result) + format_to_n(OutputIt out, std::size_t n, const S &format_str, + const Args &... args) { internal::check_format_string(format_str); - typedef FMT_CHAR(String) Char; - format_arg_store, Args...> as{ args... }; + typedef FMT_CHAR(S) Char; + format_arg_store, Args...> as(args...); return vformat_to_n(out, n, internal::to_string_view(format_str), format_to_n_args(as)); }