From 09e2ac5e4686942eb2e79f5b27c901d392176710 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 10 Apr 2019 07:45:44 -0700 Subject: [PATCH] Update --- include/format | 95 +++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/include/format b/include/format index 0cdbeb47..167a5fba 100644 --- a/include/format +++ b/include/format @@ -37,20 +37,17 @@ namespace std { template class basic_format_parse_context; using format_parse_context = basic_format_parse_context; using wformat_parse_context = basic_format_parse_context; - - template FMT_REQUIRES(OutputIterator) - class basic_format_context; + + template class basic_format_context; using format_context = basic_format_context< - /* unspecified */ std::back_insert_iterator>, - char>; + /* unspecified */ std::back_insert_iterator>, char>; using wformat_context = basic_format_context< - /* unspecified */ std::back_insert_iterator>, - wchar_t>; + /* unspecified */ std::back_insert_iterator>, wchar_t>; template struct formatter { formatter() = delete; }; - + // [format.arguments], arguments template class basic_format_arg; @@ -63,8 +60,8 @@ namespace std { using format_args = basic_format_args; using wformat_args = basic_format_args; - template - using format_args_t = basic_format_args>; + template + using format_args_t = basic_format_args>; template format_arg_store @@ -82,28 +79,28 @@ namespace std { string vformat(string_view fmt, format_args args); wstring vformat(wstring_view fmt, wformat_args args); - template) O, class... Args> - O format_to(O out, string_view fmt, const Args&... args); - template) O, class... Args> - O format_to(O out, wstring_view fmt, const Args&... args); + template + Out format_to(Out out, string_view fmt, const Args&... args); + template + Out format_to(Out out, wstring_view fmt, const Args&... args); - template) O> - O vformat_to(O out, string_view fmt, format_args_t args); - template) O> - O vformat_to(O out, wstring_view fmt, format_args_t args); + template + Out vformat_to(Out out, string_view fmt, format_args_t args); + template + Out vformat_to(Out out, wstring_view fmt, format_args_t args); - template + template struct format_to_n_result { - O out; - iter_difference_t size; + Out out; + iter_difference_t size; }; - - template) O, class... Args> - format_to_n_result format_to_n(O out, iter_difference_t n, - string_view fmt, const Args&... args); - template) O, class... Args> - format_to_n_result format_to_n(O out, iter_difference_t n, - wstring_view fmt, const Args&... args); + + template + format_to_n_result format_to_n(Out out, iter_difference_t n, + string_view fmt, const Args&... args); + template + format_to_n_result format_to_n(Out out, iter_difference_t n, + wstring_view fmt, const Args&... args); template size_t formatted_size(string_view fmt, const Args&... args); @@ -229,6 +226,8 @@ template void basic_format_context::advance_to(typename basic_format_context::iterator it) { out_ = it; } } +namespace std { +namespace detail { template constexpr bool is_standard_integer_v = std::is_same_v || @@ -245,6 +244,10 @@ constexpr bool is_standard_unsigned_integer_v = std::is_same_v || std::is_same_v; +template struct formatter; +} +} + // http://fmtlib.net/Text%20Formatting.html#format.arg namespace std { template @@ -269,10 +272,11 @@ namespace std { std::is_same_v || std::is_same_v || (std::is_same_v && std::is_same_v) || - is_standard_integer_v || - is_standard_unsigned_integer_v + detail::is_standard_integer_v || + detail::is_standard_unsigned_integer_v || + is_default_constructible_v> >> - explicit basic_format_arg(I n) noexcept; // exposition only + explicit basic_format_arg(const I& n) noexcept; // exposition only explicit basic_format_arg(float n) noexcept; // exposition only explicit basic_format_arg(double n) noexcept; // exposition only explicit basic_format_arg(long double n) noexcept; // exposition only @@ -290,10 +294,6 @@ namespace std { template>> explicit basic_format_arg(const T* p) noexcept; // exposition only - template && is_default_constructible_v>>> - explicit basic_format_arg(const T& v) noexcept; // exposition only - //template // friend auto std::visit_format_arg(Visitor&& vis, basic_format_arg arg); @@ -301,6 +301,8 @@ namespace std { friend format_arg_store make_format_args(const Args&... args); // exposition only + template friend struct detail::formatter; + public: basic_format_arg() noexcept; @@ -314,19 +316,21 @@ basic_format_arg::basic_format_arg() noexcept {} template template -/* explicit */ basic_format_arg::basic_format_arg(I n) noexcept { - if (std::is_same_v || std::is_same_v) +/* explicit */ basic_format_arg::basic_format_arg(const I& n) noexcept { + if constexpr (std::is_same_v || std::is_same_v) value = n; - else if (std::is_same_v && std::is_same_v) + else if constexpr (std::is_same_v && std::is_same_v) value = static_cast(n); - else if (is_standard_integer_v && sizeof(I) <= sizeof(int)) + else if constexpr (detail::is_standard_integer_v && sizeof(I) <= sizeof(int)) value = static_cast(n); - else if (is_standard_unsigned_integer_v && sizeof(I) <= sizeof(unsigned)) + else if constexpr (detail::is_standard_unsigned_integer_v && sizeof(I) <= sizeof(unsigned)) value = static_cast(n); - else if (is_standard_integer_v) + else if constexpr (detail::is_standard_integer_v) value = static_cast(n); - else if (is_standard_unsigned_integer_v) + else if constexpr (detail::is_standard_unsigned_integer_v) value = static_cast(n); + else if constexpr (is_default_constructible_v>) + value = handle(n); } template @@ -367,11 +371,6 @@ template template /* explicit */ basic_format_arg::basic_format_arg(const T* p) noexcept : value(p) {} -template -template -/* explicit */ basic_format_arg::basic_format_arg(const T& v) noexcept - : value(handle(v)) {} - template /* explicit */ basic_format_arg::operator bool() const noexcept { return !holds_alternative(value); @@ -387,6 +386,8 @@ namespace std { template explicit handle(const T& val) noexcept; // exposition only + friend class basic_format_arg; + public: void format(basic_format_parse_context&, Context& ctx) const; };