diff --git a/format.h b/format.h index 9a7e0253..f0d64967 100644 --- a/format.h +++ b/format.h @@ -1211,17 +1211,27 @@ class MakeValue : public Arg { static uint64_t type(const NamedArg &) { return Arg::NAMED_ARG; } }; +template +class MakeArg : public Arg { +public: + MakeArg() { + type = Arg::NONE; + } + + template + MakeArg(const T &value) + : Arg(MakeValue(value)) { + type = static_cast(MakeValue::type(value)); + } +}; + template struct NamedArg : Arg { BasicStringRef name; - typedef internal::MakeValue< BasicFormatter > MakeValue; - template NamedArg(BasicStringRef argname, const T &value) - : Arg(MakeValue(value)), name(argname) { - type = static_cast(MakeValue::type(value)); - } + : Arg(MakeArg< BasicFormatter >(value)), name(argname) {} }; #define FMT_DISPATCH(call) static_cast(this)->call @@ -1931,44 +1941,29 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) { return make_type(first) | (make_type(tail...) << 4); } -inline void do_set_types(Arg *) {} - -template -inline void do_set_types(Arg *args, const T &arg, const Args & ... tail) { - args->type = static_cast( - MakeValue< BasicFormatter >::type(arg)); - do_set_types(args + 1, tail...); +template +inline void store_args(Arg *args) { + *args = MakeArg(); } -template -inline void set_types(Arg *array, const Args & ... args) { - if (check(sizeof...(Args) > ArgList::MAX_PACKED_ARGS)) - do_set_types(array, args...); - array[sizeof...(Args)].type = Arg::NONE; +template +inline void store_args(Arg *args, const T &arg, const Args & ... tail) { + *args = MakeArg(arg); + store_args(args + 1, tail...); } -template -inline void set_types(Value *, const Args & ...) { - // Do nothing as types are passed separately from values. -} - -template +template inline void store_args(Value *) {} -template -inline void store_args(Arg *args, const T &arg, const Args & ... tail) { - // Assign only the Value subobject of Arg and don't overwrite type (if any) - // that is assigned by set_types. - Value &value = *args; - value = MakeValue(arg); +template +inline void store_args(Value *args, const T &arg, const Args & ... tail) { + *args = MakeValue(arg); store_args(args + 1, tail...); } template ArgList make_arg_list(typename ArgArray::Type array, const Args & ... args) { - if (check(sizeof...(Args) >= ArgList::MAX_PACKED_ARGS)) - set_types(array, args...); store_args(array, args...); return ArgList(make_type(args...), array); } @@ -2944,10 +2939,8 @@ void format(BasicFormatter &f, const Char *&format_str, const T &value) { output << value; BasicStringRef str(&buffer[0], format_buf.size()); - typedef internal::MakeValue< BasicFormatter > MakeValue; - internal::Arg arg = MakeValue(str); - arg.type = static_cast(MakeValue::type(str)); - format_str = f.format(format_str, arg); + typedef internal::MakeArg< BasicFormatter > MakeArg; + format_str = f.format(format_str, MakeArg(str)); } // Reports a system error without throwing an exception.