From 0f0b42861bdbb784d13431d62b7b78039a835662 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 7 Jun 2019 17:30:18 -0700 Subject: [PATCH] Cleanup --- include/fmt/core.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index f67b34c9..daed6e3d 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -376,8 +376,7 @@ template struct is_compile_string : std::is_base_of {}; template ::value)> -FMT_CONSTEXPR basic_string_view to_string_view( - const S& s) { +constexpr basic_string_view to_string_view(const S& s) { return s; } @@ -610,7 +609,6 @@ using has_fallback_formatter = std::is_constructible>; template struct named_arg_base; - template struct named_arg; enum type { @@ -692,6 +690,7 @@ template class value { string_value sstring; string_value ustring; custom_value custom; + const named_arg_base* named_arg; }; FMT_CONSTEXPR value(int val = 0) : int_value(val) {} @@ -728,9 +727,7 @@ template class value { internal::fallback_formatter>>; } - const named_arg_base& as_named_arg() { - return *static_cast*>(pointer); - } + value(const named_arg_base& arg) { named_arg = &arg; } private: // Formats an argument of a custom type, such as a user-defined class. @@ -880,12 +877,12 @@ inline init make_value(const T& val) { return val; } -template -init make_value( - const named_arg& val) { +template +init&, named_arg_type> make_value( + const named_arg& val) { basic_format_arg arg = make_arg(val.value); std::memcpy(val.data, &arg, sizeof(arg)); - return static_cast(&val); + return val; } // Maximum number of arguments with packed types. @@ -1012,7 +1009,7 @@ template class arg_map { unsigned size_; void push_back(value val) { - const internal::named_arg_base& named = val.as_named_arg(); + const auto& named = *val.named_arg; map_[size_] = entry{named.name, named.template deserialize()}; ++size_; } @@ -1157,8 +1154,8 @@ template class format_arg_store { public: static constexpr unsigned long long TYPES = - is_packed ? internal::get_types() - : internal::is_unpacked_bit | num_args; + is_packed ? internal::get_types() + : internal::is_unpacked_bit | num_args; format_arg_store(const Args&... args) : data_{internal::make_arg(args)...} {} @@ -1254,7 +1251,7 @@ template class basic_format_args { format_arg get(size_type index) const { format_arg arg = do_get(index); if (arg.type_ == internal::named_arg_type) - arg = arg.value_.as_named_arg().template deserialize(); + arg = arg.value_.named_arg->template deserialize(); return arg; }