Get rid of FMT_VARIADIC_VOID

This commit is contained in:
Victor Zverovich 2016-08-27 08:16:49 -07:00
parent 4ece95a754
commit 0d8aca8de3
5 changed files with 12 additions and 27 deletions

View File

@ -485,7 +485,7 @@ FMT_FUNC void report_windows_error(
FMT_FUNC void vprint(std::FILE *f, CStringRef format_str, format_args args) {
MemoryWriter w;
w.write(format_str, args);
w.vwrite(format_str, args);
std::fwrite(w.data(), 1, w.size(), f);
}

View File

@ -2181,14 +2181,6 @@ class BasicFormatter : private internal::FormatterBase {
# define FMT_ASSIGN_wchar_t(n) \
arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<wchar_t> >(v##n)
// Defines a variadic function returning void.
# define FMT_VARIADIC_VOID(func, arg_type) \
template <typename... Args> \
void func(arg_type arg0, const Args & ... args) { \
auto store = fmt::make_format_args< fmt::BasicFormatter<Char> >(args...); \
func(arg0, fmt::format_args(store)); \
}
// Defines a variadic constructor.
# define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \
template <typename... Args> \
@ -2449,6 +2441,10 @@ class BasicWriter {
return std::basic_string<Char>(&buffer_[0], buffer_.size());
}
void vwrite(BasicCStringRef<Char> format, format_args args) {
BasicFormatter<Char>(args, *this).format(format);
}
/**
\rst
Writes formatted data.
@ -2474,10 +2470,10 @@ class BasicWriter {
See also :ref:`syntax`.
\endrst
*/
void write(BasicCStringRef<Char> format, format_args args) {
BasicFormatter<Char>(args, *this).format(format);
template <typename... Args>
void write(BasicCStringRef<Char> format, const Args & ... args) {
vwrite(format, make_format_args<fmt::BasicFormatter<Char>>(args...));
}
FMT_VARIADIC_VOID(write, BasicCStringRef<Char>)
BasicWriter &operator<<(int value) {
write_decimal(value);
@ -3134,7 +3130,7 @@ inline void print_colored(Color c, CStringRef format_str,
inline std::string vformat(CStringRef format_str, format_args args) {
MemoryWriter w;
w.write(format_str, args);
w.vwrite(format_str, args);
return w.str();
}
@ -3154,7 +3150,7 @@ inline std::string format(CStringRef format_str, const Args & ... args) {
inline std::wstring vformat(WCStringRef format_str, format_args args) {
WMemoryWriter w;
w.write(format_str, args);
w.vwrite(format_str, args);
return w.str();
}

View File

@ -30,7 +30,7 @@ FMT_FUNC void write(std::ostream &os, Writer &w) {
FMT_FUNC void vprint(std::ostream &os, CStringRef format_str,
format_args args) {
MemoryWriter w;
w.write(format_str, args);
w.vwrite(format_str, args);
internal::write(os, w);
}
} // namespace fmt

View File

@ -1566,7 +1566,7 @@ TEST(StrTest, Convert) {
std::string vformat_message(int id, const char *format, fmt::format_args args) {
MemoryWriter w;
w.write("[{}] ", id);
w.write(format, args);
w.vwrite(format, args);
return w.str();
}

View File

@ -74,14 +74,3 @@ int result;
}
MAKE_TEST(test_func)
typedef char Char;
MAKE_TEST(test_variadic_void)
FMT_VARIADIC_VOID(test_variadic_void, const char *)
TEST(UtilTest, VariadicVoid) {
result = 0;
test_variadic_void("", 10, 20, 30, 40, 50, 60, 70, 80, 90, 100);
EXPECT_EQ(550, result);
}