diff --git a/include/fmt/color.h b/include/fmt/color.h index b29ab082..5c9b0491 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -556,7 +556,7 @@ std::basic_string vformat( } } // namespace internal -template ::type> +template > void vprint(std::FILE* f, const text_style& ts, const S& format, basic_format_args::type> args) { bool has_style = false; @@ -587,13 +587,12 @@ void vprint(std::FILE* f, const text_style& ts, const S& format, fmt::print(fmt::emphasis::bold | fg(fmt::color::red), "Elapsed time: {0:.2f} seconds", 1.23); */ -template ::value)> -void print(std::FILE* f, const text_style& ts, const String& format_str, +template ::value)> +void print(std::FILE* f, const text_style& ts, const S& format_str, const Args&... args) { internal::check_format_string(format_str); - typedef typename internal::char_t::type char_t; - typedef typename buffer_context::type context_t; + typedef typename buffer_context >::type context_t; format_arg_store as{args...}; vprint(f, ts, format_str, basic_format_args(as)); } @@ -605,14 +604,13 @@ void print(std::FILE* f, const text_style& ts, const String& format_str, fmt::print(fmt::emphasis::bold | fg(fmt::color::red), "Elapsed time: {0:.2f} seconds", 1.23); */ -template ::value)> -void print(const text_style& ts, const String& format_str, - const Args&... args) { +template ::value)> +void print(const text_style& ts, const S& format_str, const Args&... args) { return print(stdout, ts, format_str, args...); } -template +template > inline std::basic_string vformat( const text_style& ts, const S& format_str, basic_format_args::type> args) { @@ -631,10 +629,9 @@ inline std::basic_string vformat( "The answer is {}", 42); \endrst */ -template -inline std::basic_string format(const text_style& ts, - const S& format_str, - const Args&... args) { +template > +inline std::basic_string format(const text_style& ts, const S& format_str, + const Args&... args) { return internal::vformat(ts, to_string_view(format_str), {internal::make_args_checked(format_str, args...)}); } diff --git a/include/fmt/core.h b/include/fmt/core.h index e9cea570..3298b05f 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -617,7 +617,7 @@ struct is_string template <> struct is_string; template <> struct is_string; -template struct char_t { +template struct char_t_impl { typedef decltype(to_string_view(std::declval())) result; typedef typename result::char_type type; }; @@ -883,7 +883,7 @@ FMT_CONSTEXPR11 init, string_type> make_value(const S& val) { // Handle adapted strings. static_assert(std::is_same::type>::value, + typename internal::char_t_impl::type>::value, "mismatch between char-types of context and argument"); return to_string_view(val); } @@ -1311,8 +1311,7 @@ struct wformat_args : basic_format_args { }; /** String's character type. */ -template using char_t = typename internal::char_t::type; -#define FMT_CHAR(S) fmt::char_t +template using char_t = typename internal::char_t_impl::type; namespace internal { template @@ -1353,8 +1352,8 @@ template ::value)> -inline format_arg_store::type, Args...> + typename Char = enable_if_t::value, char_t>> +inline format_arg_store::type, Args...> make_args_checked(const S& format_str, const Args&... args) { internal::check_format_string(format_str); return {args...}; @@ -1386,8 +1385,8 @@ typename buffer_context::type::iterator vformat_to( fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23)); \endrst */ -template -inline internal::named_arg arg(const S& name, const T& arg) { +template > +inline internal::named_arg arg(const S& name, const T& arg) { static_assert(internal::is_string::value, ""); return {name, arg}; } @@ -1404,13 +1403,23 @@ struct is_contiguous> : std::true_type {}; template struct is_contiguous> : std::true_type {}; +template +struct is_contiguous_back_insert_iterator : std::false_type {}; + +template +struct is_contiguous_back_insert_iterator> + : is_contiguous {}; + /** Formats a string and writes the output to ``out``. */ -template -typename std::enable_if::value, - std::back_insert_iterator>::type -vformat_to(std::back_insert_iterator out, const S& format_str, - basic_format_args::type> args) { - internal::container_buffer buf(internal::get_container(out)); +template ::value, char_t>> +OutputIt vformat_to( + OutputIt out, const S& format_str, + basic_format_args::type> args) { + using container = typename std::remove_reference::type; + internal::container_buffer buf((internal::get_container(out))); internal::vformat_to(buf, to_string_view(format_str), args); return out; } @@ -1425,8 +1434,8 @@ inline std::back_insert_iterator format_to( {internal::make_args_checked(format_str, args...)}); } -template ::value)> +template ::value, char_t>> inline std::basic_string vformat( const S& format_str, basic_format_args::type> args) { @@ -1443,11 +1452,12 @@ inline std::basic_string vformat( std::string message = fmt::format("The answer is {}", 42); \endrst */ -// Pass fmt::char_t as a default template parameter instead of using -// std::basic_string> to reduce the symbol size. +// Pass char_t as a default template parameter instead of using +// std::basic_string> to reduce the symbol size. template ::value, char_t>> -inline std::basic_string format(const S& format_str, const Args&... args) { +inline std::basic_string format(const S& format_str, + const Args&... args) { return internal::vformat(to_string_view(format_str), {internal::make_args_checked(format_str, args...)}); } diff --git a/include/fmt/format.h b/include/fmt/format.h index 42846f90..c8ce2f39 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1805,10 +1805,11 @@ struct string_view_metadata { : offset_(view.data() - primary_string.data()), size_(view.size()) {} FMT_CONSTEXPR string_view_metadata(std::size_t offset, std::size_t size) : offset_(offset), size_(size) {} - template ::value)> - FMT_CONSTEXPR basic_string_view to_view(S&& str) const { + template ::value, char_t>> + FMT_CONSTEXPR basic_string_view to_view(S&& str) const { const auto view = to_string_view(str); - return basic_string_view(view.data() + offset_, size_); + return basic_string_view(view.data() + offset_, size_); } std::size_t offset_; @@ -3384,7 +3385,7 @@ typename buffer_context::type::iterator internal::vformat_to( args); } -template , FMT_ENABLE_IF(internal::is_string::value)> inline typename buffer_context::type::iterator vformat_to( internal::buffer& buf, const S& format_str, @@ -3393,12 +3394,12 @@ inline typename buffer_context::type::iterator vformat_to( } template ::type> + typename Char = enable_if_t::value, char_t>> inline typename buffer_context::type::iterator format_to( basic_memory_buffer& buf, const S& format_str, const Args&... args) { internal::check_format_string(format_str); - typedef typename buffer_context::type context; + using context = typename buffer_context::type; format_arg_store as{args...}; return internal::vformat_to(buf, to_string_view(format_str), basic_format_args(as)); @@ -3459,12 +3460,13 @@ struct format_args_t { type; }; -template ::value)> +template ::value && + !is_contiguous_back_insert_iterator::value)> inline OutputIt vformat_to( - OutputIt out, const String& format_str, - typename format_args_t::type args) { - typedef output_range range; + OutputIt out, const S& format_str, + typename format_args_t>::type args) { + typedef output_range> range; return vformat_to>(range(out), to_string_view(format_str), args); } @@ -3481,13 +3483,13 @@ inline OutputIt vformat_to( \endrst */ template -inline - typename std::enable_if::value && - internal::is_output_iterator::value, - OutputIt>::type - format_to(OutputIt out, const S& format_str, const Args&... args) { +inline OutputIt format_to(OutputIt out, const S& format_str, + const Args&... args) { + static_assert(internal::is_output_iterator::value && + internal::is_string::value, + ""); 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, to_string_view(format_str), basic_format_args(as)); @@ -3542,7 +3544,7 @@ inline 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(S) Char; + using Char = char_t; format_arg_store::type, Args...> as(args...); return vformat_to_n(out, n, to_string_view(format_str), diff --git a/include/fmt/locale.h b/include/fmt/locale.h index aeb35217..b6b4cf90 100644 --- a/include/fmt/locale.h +++ b/include/fmt/locale.h @@ -34,38 +34,39 @@ std::basic_string vformat( } } // namespace internal -template +template > inline std::basic_string vformat( const std::locale& loc, const S& format_str, basic_format_args::type> args) { return internal::vformat(loc, to_string_view(format_str), args); } -template -inline std::basic_string format(const std::locale& loc, - const S& format_str, - const Args&... args) { +template > +inline std::basic_string format(const std::locale& loc, + const S& format_str, + const Args&... args) { return internal::vformat(loc, to_string_view(format_str), {internal::make_args_checked(format_str, args...)}); } -template ::value)> -inline OutputIt vformat_to( - OutputIt out, const std::locale& loc, const String& format_str, - typename format_args_t::type args) { - typedef output_range range; +template ::value, char_t>> +inline OutputIt vformat_to(OutputIt out, const std::locale& loc, + const S& format_str, + typename format_args_t::type args) { + using range = output_range; return vformat_to>( range(out), to_string_view(format_str), args, internal::locale_ref(loc)); } template ::value&& - internal::is_output_iterator::value)> + FMT_ENABLE_IF(internal::is_output_iterator::value&& + internal::is_string::value)> inline OutputIt format_to(OutputIt out, const std::locale& loc, const S& format_str, const Args&... args) { internal::check_format_string(format_str); - typedef typename format_context_t::type context; + using context = typename format_context_t>::type; format_arg_store as{args...}; return vformat_to(out, loc, to_string_view(format_str), basic_format_args(as)); diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 47d81a90..0399108f 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -120,13 +120,13 @@ struct convert_to_int< }; template -inline void vprint( - std::basic_ostream& os, basic_string_view format_str, - basic_format_args::type> args) { +void vprint(std::basic_ostream& os, basic_string_view format_str, + basic_format_args::type> args) { basic_memory_buffer buffer; internal::vformat_to(buffer, format_str, args); internal::write(os, buffer); } + /** \rst Prints formatted data to the stream *os*. @@ -137,8 +137,8 @@ inline void vprint( \endrst */ template ::value)> -inline void print(std::basic_ostream& os, const S& format_str, + typename Char = enable_if_t::value, char_t>> +inline void print(std::basic_ostream& os, const S& format_str, const Args&... args) { vprint(os, to_string_view(format_str), {internal::make_args_checked(format_str, args...)}); diff --git a/include/fmt/prepare.h b/include/fmt/prepare.h index 7bfe73d4..7f4ff082 100644 --- a/include/fmt/prepare.h +++ b/include/fmt/prepare.h @@ -185,8 +185,8 @@ class format_preparation_handler : public internal::error_handler { template class prepared_format { public: - typedef FMT_CHAR(Format) char_type; - typedef format_part format_part_t; + using char_type = char_t; + using format_part_t = format_part; prepared_format(Format f) : format_(std::move(f)), parts_provider_(to_string_view(format_)) {} @@ -351,7 +351,7 @@ class prepared_format { template class compiletime_prepared_parts_type_provider { private: - typedef FMT_CHAR(Format) char_type; + using char_type = char_t; class count_handler { private: @@ -649,7 +649,7 @@ class parts_container { // Delegate preparing to preparator, to take advantage of a partial // specialization. template struct preparator { - typedef parts_container container; + typedef parts_container> container; typedef typename basic_prepared_format::type prepared_format_type; diff --git a/include/fmt/printf.h b/include/fmt/printf.h index f879dc83..3dbf1fc0 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -608,7 +608,7 @@ inline format_arg_store make_wprintf_args( return {args...}; } -template +template > inline std::basic_string vsprintf( const S& format, basic_format_args< @@ -629,16 +629,14 @@ inline std::basic_string vsprintf( \endrst */ template ::value)> -inline std::basic_string sprintf(const S& format, - const Args&... args) { - typedef internal::buffer buffer; - typedef typename basic_printf_context_t::type context; + typename Char = enable_if_t::value, char_t>> +inline std::basic_string sprintf(const S& format, const Args&... args) { + using context = typename basic_printf_context_t>::type; format_arg_store as{args...}; return vsprintf(to_string_view(format), basic_format_args(as)); } -template +template > inline int vfprintf( std::FILE* f, const S& format, basic_format_args< @@ -662,15 +660,14 @@ inline int vfprintf( \endrst */ template ::value)> + typename Char = enable_if_t::value, char_t>> inline int fprintf(std::FILE* f, const S& format, const Args&... args) { - typedef internal::buffer buffer; - typedef typename basic_printf_context_t::type context; + using context = typename basic_printf_context_t>::type; format_arg_store as{args...}; return vfprintf(f, to_string_view(format), basic_format_args(as)); } -template +template > inline int vprintf( const S& format, basic_format_args< @@ -692,13 +689,13 @@ template ::value)> inline int printf(const S& format_str, const Args&... args) { internal::check_format_string(format_str); - typedef internal::buffer buffer; - typedef typename basic_printf_context_t::type context; + using buffer = internal::buffer>; + using context = typename basic_printf_context_t::type; format_arg_store as{args...}; return vprintf(to_string_view(format_str), basic_format_args(as)); } -template +template > inline int vfprintf( std::basic_ostream& os, const S& format, basic_format_args< @@ -731,13 +728,11 @@ typename ArgFormatter::iterator vprintf(internal::buffer& out, fmt::fprintf(cerr, "Don't %s!", "panic"); \endrst */ -template ::value)> -inline int fprintf(std::basic_ostream& os, const S& format_str, +template > +inline int fprintf(std::basic_ostream& os, const S& format_str, const Args&... args) { internal::check_format_string(format_str); - typedef internal::buffer buffer; - typedef typename basic_printf_context_t::type context; + using context = typename basic_printf_context_t>::type; format_arg_store as{args...}; return vfprintf(os, to_string_view(format_str), basic_format_args(as));