From df4ea0c76ce084453b9f8d321b02238670f2f5b4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 10 Apr 2019 06:25:42 -0700 Subject: [PATCH] Update --- include/format | 81 +++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/include/format b/include/format index 4576adbe..0cdbeb47 100644 --- a/include/format +++ b/include/format @@ -229,6 +229,22 @@ template void basic_format_context::advance_to(typename basic_format_context::iterator it) { out_ = it; } } +template +constexpr bool is_standard_integer_v = + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v; + +template +constexpr bool is_standard_unsigned_integer_v = + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v || + std::is_same_v; + // http://fmtlib.net/Text%20Formatting.html#format.arg namespace std { template @@ -236,17 +252,27 @@ namespace std { public: class handle; + private: using char_type = typename Context::char_type; // exposition only + public: // public to workaround a bug in clang variant, const void*, handle> value; // exposition only - basic_format_arg() noexcept; - - template>> explicit basic_format_arg(I n) noexcept; // exposition only + private: + template< + FMT_CONCEPT(Integral) I, + typename = enable_if_t< + 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 + >> + explicit basic_format_arg(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 @@ -266,7 +292,17 @@ namespace std { template && is_default_constructible_v>>> - explicit basic_format_arg(const T& v) noexcept; // exposition only + explicit basic_format_arg(const T& v) noexcept; // exposition only + + //template + // friend auto std::visit_format_arg(Visitor&& vis, basic_format_arg arg); + + template + friend format_arg_store + make_format_args(const Args&... args); // exposition only + + public: + basic_format_arg() noexcept; explicit operator bool() const noexcept; }; @@ -276,38 +312,21 @@ namespace std { template basic_format_arg::basic_format_arg() noexcept {} -template -constexpr bool is_standard_integer_v = - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v; - -template -constexpr bool is_standard_unsigned_integer_v = - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v; - template template /* explicit */ basic_format_arg::basic_format_arg(I n) noexcept { if (std::is_same_v || std::is_same_v) value = n; - else if (std::is_same_v || std::is_same_v) + else if (std::is_same_v && std::is_same_v) value = static_cast(n); - else if (std::is_standard_integer_v && sizeof(I) <= sizeof(int)) + else if (is_standard_integer_v && sizeof(I) <= sizeof(int)) value = static_cast(n); - else if (std::is_standard_integer_v && sizeof(I) <= sizeof(unsigned)) + else if (is_standard_unsigned_integer_v && sizeof(I) <= sizeof(unsigned)) value = static_cast(n); - else if (std::is_standard_integer_v) + else if (is_standard_integer_v) value = static_cast(n); - else if (std::is_standard_integer_v) + else if (is_standard_unsigned_integer_v) value = static_cast(n); - else assert(false); // should be a compile-time error instead } template @@ -363,13 +382,13 @@ namespace std { template class basic_format_arg::handle { const void* ptr_; // exposition only - void (*format_)(basic_format_parse_context&, - Context&, const void*); // exposition only + void (*format_)(basic_format_parse_context&, + Context&, const void*); // exposition only - public: - template explicit handle(const T& val) noexcept; // exposition only + template explicit handle(const T& val) noexcept; // exposition only - void format(basic_format_parse_context&, Context& ctx) const; + public: + void format(basic_format_parse_context&, Context& ctx) const; }; }