diff --git a/format.h b/format.h index 7a5ab559..9f79c60d 100644 --- a/format.h +++ b/format.h @@ -759,7 +759,7 @@ template struct None {}; // A helper class template to enable or disable overloads taking wide -// characters and strings in MakeValue. +// characters and strings in MakeArg. template struct WCharHelper { typedef None Supported; @@ -807,7 +807,7 @@ struct EnableIf { typedef T type; }; // Makes an Arg object from any type. template -class MakeValue : public Arg { // TODO: rename to MakeArg +class MakeArg : public Arg { private: // The following two methods are private to disallow formatting of // arbitrary pointers. If you want to output a pointer cast it to @@ -815,19 +815,19 @@ class MakeValue : public Arg { // TODO: rename to MakeArg // of "[const] volatile char *" which is printed as bool by iostreams. // Do not implement! template - MakeValue(const T *value); + MakeArg(const T *value); template - MakeValue(T *value); + MakeArg(T *value); // The following methods are private to disallow formatting of wide // characters and strings into narrow strings as in // fmt::format("{}", L"test"); // To fix this, use a wide format string: fmt::format(L"{}", L"test"). - MakeValue(typename WCharHelper::Unsupported); - MakeValue(typename WCharHelper::Unsupported); - MakeValue(typename WCharHelper::Unsupported); - MakeValue(typename WCharHelper::Unsupported); - MakeValue(typename WCharHelper::Unsupported); + MakeArg(typename WCharHelper::Unsupported); + MakeArg(typename WCharHelper::Unsupported); + MakeArg(typename WCharHelper::Unsupported); + MakeArg(typename WCharHelper::Unsupported); + MakeArg(typename WCharHelper::Unsupported); void set_string(StringRef str) { string.value = str.c_str(); @@ -849,10 +849,10 @@ class MakeValue : public Arg { // TODO: rename to MakeArg } public: - MakeValue() {} + MakeArg() {} #define FMT_MAKE_VALUE(Type, field, TYPE) \ - MakeValue(Type value) { field = value; } \ + MakeArg(Type value) { field = value; } \ static uint64_t type(Type) { return Arg::TYPE; } FMT_MAKE_VALUE(bool, int_value, INT) @@ -861,7 +861,7 @@ class MakeValue : public Arg { // TODO: rename to MakeArg FMT_MAKE_VALUE(int, int_value, INT) FMT_MAKE_VALUE(unsigned, uint_value, UINT) - MakeValue(long value) { + MakeArg(long value) { // To minimize the number of types we need to deal with, long is // translated either to int or to long long depending on its size. if (sizeof(long) == sizeof(int)) @@ -873,7 +873,7 @@ class MakeValue : public Arg { // TODO: rename to MakeArg return sizeof(long) == sizeof(int) ? Arg::INT : Arg::LONG_LONG; } - MakeValue(unsigned long value) { + MakeArg(unsigned long value) { if (sizeof(unsigned long) == sizeof(unsigned)) uint_value = static_cast(value); else @@ -893,13 +893,13 @@ class MakeValue : public Arg { // TODO: rename to MakeArg FMT_MAKE_VALUE(unsigned char, int_value, CHAR) FMT_MAKE_VALUE(char, int_value, CHAR) - MakeValue(typename WCharHelper::Supported value) { + MakeArg(typename WCharHelper::Supported value) { int_value = value; } static uint64_t type(wchar_t) { return Arg::CHAR; } #define FMT_MAKE_STR_VALUE(Type, TYPE) \ - MakeValue(Type value) { set_string(value); } \ + MakeArg(Type value) { set_string(value); } \ static uint64_t type(Type) { return Arg::TYPE; } FMT_MAKE_VALUE(char *, string.value, CSTRING) @@ -910,7 +910,7 @@ class MakeValue : public Arg { // TODO: rename to MakeArg FMT_MAKE_STR_VALUE(StringRef, STRING) #define FMT_MAKE_WSTR_VALUE(Type, TYPE) \ - MakeValue(typename WCharHelper::Supported value) { \ + MakeArg(typename WCharHelper::Supported value) { \ set_string(value); \ } \ static uint64_t type(Type) { return Arg::TYPE; } @@ -924,15 +924,15 @@ class MakeValue : public Arg { // TODO: rename to MakeArg FMT_MAKE_VALUE(const void *, pointer, POINTER) template - MakeValue(const T &value, - typename EnableIf::value, int>::type = 0) { + MakeArg(const T &value, + typename EnableIf::value, int>::type = 0) { custom.value = &value; custom.format = &format_custom_arg; } template - MakeValue(const T &value, - typename EnableIf::value, int>::type = 0) { + MakeArg(const T &value, + typename EnableIf::value, int>::type = 0) { int_value = value; } @@ -1419,7 +1419,7 @@ namespace internal { inline uint64_t make_type() { return 0; } template -inline uint64_t make_type(const T &arg) { return MakeValue::type(arg); } +inline uint64_t make_type(const T &arg) { return MakeArg::type(arg); } #if FMT_USE_VARIADIC_TEMPLATES template @@ -1451,8 +1451,8 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) { # define FMT_MAKE_TEMPLATE_ARG(n) typename T##n # define FMT_MAKE_ARG_TYPE(n) T##n # define FMT_MAKE_ARG(n) const T##n &v##n -# define FMT_MAKE_REF_char(n) fmt::internal::MakeValue(v##n) -# define FMT_MAKE_REF_wchar_t(n) fmt::internal::MakeValue(v##n) +# define FMT_MAKE_REF_char(n) fmt::internal::MakeArg(v##n) +# define FMT_MAKE_REF_wchar_t(n) fmt::internal::MakeArg(v##n) #if FMT_USE_VARIADIC_TEMPLATES // Defines a variadic function returning void. @@ -1461,7 +1461,7 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) { void func(arg_type arg1, const Args & ... args) { \ const fmt::internal::Arg array[ \ fmt::internal::NonZero::VALUE] = { \ - fmt::internal::MakeValue(args)... \ + fmt::internal::MakeArg(args)... \ }; \ func(arg1, ArgList(fmt::internal::make_type(args...), array)); \ } @@ -1470,17 +1470,17 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) { # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ template \ ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \ - using fmt::internal::MakeValue; \ + using fmt::internal::MakeArg; \ const fmt::internal::Arg array[ \ fmt::internal::NonZero::VALUE] = { \ - MakeValue(args)... \ + MakeArg(args)... \ }; \ func(arg0, arg1, ArgList(fmt::internal::make_type(args...), array)); \ } #else -# define FMT_MAKE_REF(n) fmt::internal::MakeValue(v##n) +# define FMT_MAKE_REF(n) fmt::internal::MakeArg(v##n) # define FMT_MAKE_REF2(n) v##n // Defines a wrapper for a function taking one argument of type arg_type @@ -2301,9 +2301,9 @@ void format(BasicFormatter &f, const Char *&format_str, const T &value) { std::basic_ostringstream os; os << value; std::basic_string str = os.str(); - internal::Arg arg = internal::MakeValue(str); + internal::Arg arg = internal::MakeArg(str); arg.type = static_cast( - internal::MakeValue::type(str)); + internal::MakeArg::type(str)); format_str = f.format(format_str, arg); } @@ -2605,7 +2605,7 @@ inline void set_types(Arg *) {} template inline void set_types(Arg *args, const T &arg, const Args & ... tail) { - args->type = static_cast(MakeValue::type(arg)); + args->type = static_cast(MakeArg::type(arg)); set_types(args + 1, tail...); } } @@ -2616,9 +2616,7 @@ inline void set_types(Arg *args, const T &arg, const Args & ... tail) { ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \ const Args & ... args) { \ using fmt::internal::Arg; \ - Arg array[sizeof...(Args) + 1] = { \ - fmt::internal::MakeValue(args)... \ - }; \ + Arg array[sizeof...(Args) + 1] = {fmt::internal::MakeArg(args)...}; \ if (sizeof...(Args) > fmt::ArgList::MAX_PACKED_ARGS) { \ set_types(array, args...); \ array[sizeof...(Args)].type = Arg::NONE; \ diff --git a/test/util-test.cc b/test/util-test.cc index 3bca3d46..07b2a29c 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -66,9 +66,8 @@ std::basic_ostream &operator<<(std::basic_ostream &os, Test) { template Arg make_arg(const T &value) { - Arg arg = fmt::internal::MakeValue(value); - arg.type = static_cast( - fmt::internal::MakeValue::type(value)); + Arg arg = fmt::internal::MakeArg(value); + arg.type = static_cast(fmt::internal::MakeArg::type(value)); return arg; } } // namespace