Remove unnecessary template arg from basic_format_args

This commit is contained in:
Victor Zverovich 2016-12-30 10:19:38 -08:00
parent f69786a715
commit 939aff2936
3 changed files with 20 additions and 22 deletions

View File

@ -1327,7 +1327,7 @@ basic_format_arg<Context> make_arg(const T &value);
struct monostate {}; struct monostate {};
template <typename Context, typename Char> template <typename Context>
class basic_format_args; class basic_format_args;
// A formatting argument. It is a trivially copyable/constructible type to // A formatting argument. It is a trivially copyable/constructible type to
@ -1345,7 +1345,7 @@ class basic_format_arg {
friend typename std::result_of<Visitor(int)>::type friend typename std::result_of<Visitor(int)>::type
visit(Visitor &&vis, basic_format_arg<Ctx> arg); visit(Visitor &&vis, basic_format_arg<Ctx> arg);
friend class basic_format_args<Context, typename Context::char_type>; friend class basic_format_args<Context>;
friend class internal::ArgMap<Context>; friend class internal::ArgMap<Context>;
public: public:
@ -1553,7 +1553,7 @@ inline format_arg_store<format_context, Args...>
} }
/** Formatting arguments. */ /** Formatting arguments. */
template <typename Context, typename Char> template <typename Context>
class basic_format_args { class basic_format_args {
public: public:
typedef unsigned size_type; typedef unsigned size_type;
@ -1626,8 +1626,8 @@ class basic_format_args {
} }
}; };
typedef basic_format_args<basic_format_context<char>, char> format_args; typedef basic_format_args<format_context> format_args;
typedef basic_format_args<basic_format_context<wchar_t>, wchar_t> wformat_args; typedef basic_format_args<wformat_context> wformat_args;
enum Alignment { enum Alignment {
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
@ -1863,7 +1863,7 @@ class ArgMap {
MapType map_; MapType map_;
public: public:
void init(const basic_format_args<Context, Char> &args); void init(const basic_format_args<Context> &args);
const basic_format_arg<Context> const basic_format_arg<Context>
*find(const fmt::BasicStringRef<Char> &name) const { *find(const fmt::BasicStringRef<Char> &name) const {
@ -1878,7 +1878,7 @@ class ArgMap {
}; };
template <typename Context> template <typename Context>
void ArgMap<Context>::init(const basic_format_args<Context, Char> &args) { void ArgMap<Context>::init(const basic_format_args<Context> &args) {
if (!map_.empty()) if (!map_.empty())
return; return;
typedef internal::NamedArg<Context> NamedArg; typedef internal::NamedArg<Context> NamedArg;
@ -2050,18 +2050,17 @@ template <typename Char, typename Context>
class format_context_base { class format_context_base {
private: private:
const Char *ptr_; const Char *ptr_;
basic_format_args<Context, Char> args_; basic_format_args<Context> args_;
int next_arg_index_; int next_arg_index_;
protected: protected:
typedef basic_format_arg<Context> format_arg; typedef basic_format_arg<Context> format_arg;
format_context_base(const Char *format_str, format_context_base(const Char *format_str, basic_format_args<Context> args)
basic_format_args<Context, Char> args)
: ptr_(format_str), args_(args), next_arg_index_(0) {} : ptr_(format_str), args_(args), next_arg_index_(0) {}
~format_context_base() {} ~format_context_base() {}
basic_format_args<Context, Char> args() const { return args_; } basic_format_args<Context> args() const { return args_; }
// Returns the argument with specified index. // Returns the argument with specified index.
format_arg do_get_arg(unsigned arg_index, const char *&error) { format_arg do_get_arg(unsigned arg_index, const char *&error) {
@ -2157,7 +2156,7 @@ class basic_format_context :
\endrst \endrst
*/ */
basic_format_context(const Char *format_str, basic_format_context(const Char *format_str,
basic_format_args<basic_format_context, Char> args) basic_format_args<basic_format_context> args)
: Base(format_str, args) {} : Base(format_str, args) {}
// Parses argument id and returns corresponding argument. // Parses argument id and returns corresponding argument.
@ -2394,7 +2393,7 @@ class BasicWriter {
} }
void vwrite(BasicCStringRef<Char> format, void vwrite(BasicCStringRef<Char> format,
basic_format_args<basic_format_context<Char>, Char> args); basic_format_args<basic_format_context<Char>> args);
/** /**
\rst \rst
Writes formatted data. Writes formatted data.
@ -3578,7 +3577,7 @@ void do_format_arg(BasicWriter<Char> &writer, basic_format_arg<Context> arg,
/** Formats arguments and writes the output to the writer. */ /** Formats arguments and writes the output to the writer. */
template <typename ArgFormatter, typename Char, typename Context> template <typename ArgFormatter, typename Char, typename Context>
void vformat(BasicWriter<Char> &writer, BasicCStringRef<Char> format_str, void vformat(BasicWriter<Char> &writer, BasicCStringRef<Char> format_str,
basic_format_args<Context, Char> args) { basic_format_args<Context> args) {
basic_format_context<Char> ctx(format_str.c_str(), args); basic_format_context<Char> ctx(format_str.c_str(), args);
const Char *&s = ctx.ptr(); const Char *&s = ctx.ptr();
const Char *start = s; const Char *start = s;
@ -3604,7 +3603,7 @@ void vformat(BasicWriter<Char> &writer, BasicCStringRef<Char> format_str,
template <typename Char> template <typename Char>
inline void BasicWriter<Char>::vwrite( inline void BasicWriter<Char>::vwrite(
BasicCStringRef<Char> format, BasicCStringRef<Char> format,
basic_format_args<basic_format_context<Char>, Char> args) { basic_format_args<basic_format_context<Char>> args) {
vformat<ArgFormatter<Char>>(*this, format, args); vformat<ArgFormatter<Char>>(*this, format, args);
} }
} // namespace fmt } // namespace fmt

View File

@ -282,7 +282,7 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
/** Formats an argument of a custom (user-defined) type. */ /** Formats an argument of a custom (user-defined) type. */
void operator()(internal::CustomValue<Char> c) { void operator()(internal::CustomValue<Char> c) {
const Char format_str[] = {'}', '\0'}; const Char format_str[] = {'}', '\0'};
auto args = basic_format_args<basic_format_context<Char>, Char>(); auto args = basic_format_args<basic_format_context<Char>>();
basic_format_context<Char> ctx(format_str, args); basic_format_context<Char> ctx(format_str, args);
c.format(this->writer(), c.value, &ctx); c.format(this->writer(), c.value, &ctx);
} }
@ -322,7 +322,7 @@ class printf_context :
\endrst \endrst
*/ */
explicit printf_context(BasicCStringRef<Char> format_str, explicit printf_context(BasicCStringRef<Char> format_str,
basic_format_args<printf_context, Char> args) basic_format_args<printf_context> args)
: Base(format_str.c_str(), args) {} : Base(format_str.c_str(), args) {}
/** Formats stored arguments and writes the output to the writer. */ /** Formats stored arguments and writes the output to the writer. */
@ -510,11 +510,11 @@ void format_value(BasicWriter<Char> &w, const T &value,
template <typename Char> template <typename Char>
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format,
basic_format_args<printf_context<Char>, Char> args) { basic_format_args<printf_context<Char>> args) {
printf_context<Char>(format, args).format(w); printf_context<Char>(format, args).format(w);
} }
typedef basic_format_args<printf_context<char>, char> printf_args; typedef basic_format_args<printf_context<char>> printf_args;
inline std::string vsprintf(CStringRef format, printf_args args) { inline std::string vsprintf(CStringRef format, printf_args args) {
MemoryWriter w; MemoryWriter w;
@ -537,8 +537,7 @@ inline std::string sprintf(CStringRef format_str, const Args & ... args) {
} }
inline std::wstring vsprintf( inline std::wstring vsprintf(
WCStringRef format, WCStringRef format, basic_format_args<printf_context<wchar_t>> args) {
basic_format_args<printf_context<wchar_t>, wchar_t> args) {
WMemoryWriter w; WMemoryWriter w;
printf(w, format, args); printf(w, format, args);
return w.str(); return w.str();

View File

@ -63,7 +63,7 @@ typedef fmt::printf_context<char, CustomPrintfArgFormatter>
std::string custom_vsprintf( std::string custom_vsprintf(
const char* format_str, const char* format_str,
fmt::basic_format_args<CustomPrintfFormatter, char> args) { fmt::basic_format_args<CustomPrintfFormatter> args) {
fmt::MemoryWriter writer; fmt::MemoryWriter writer;
CustomPrintfFormatter formatter(format_str, args); CustomPrintfFormatter formatter(format_str, args);
formatter.format(writer); formatter.format(writer);