Skip to content

Commit 42a6753

Browse files
committed
Merge #8000: tinyformat: force USE_VARIADIC_TEMPLATES
08d7b56 util: switch LogPrint and error to variadic templates (Wladimir J. van der Laan) 9eaa0af tinyformat: force USE_VARIADIC_TEMPLATES (Wladimir J. van der Laan)
2 parents 8206835 + 08d7b56 commit 42a6753

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

src/tinyformat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace tfm = tinyformat;
113113

114114
// Define for C++11 variadic templates which make the code shorter & more
115115
// general. If you don't define this, C++11 support is autodetected below.
116-
// #define TINYFORMAT_USE_VARIADIC_TEMPLATES
116+
#define TINYFORMAT_USE_VARIADIC_TEMPLATES
117117

118118

119119
//------------------------------------------------------------------------------

src/util.h

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,40 +76,33 @@ int LogPrintStr(const std::string &str);
7676

7777
#define LogPrintf(...) LogPrint(NULL, __VA_ARGS__)
7878

79-
/**
80-
* When we switch to C++11, this can be switched to variadic templates instead
81-
* of this macro-based construction (see tinyformat.h).
82-
*/
83-
#define MAKE_ERROR_AND_LOG_FUNC(n) \
84-
/** Print to debug.log if -debug=category switch is given OR category is NULL. */ \
85-
template<TINYFORMAT_ARGTYPES(n)> \
86-
static inline int LogPrint(const char* category, const char* format, TINYFORMAT_VARARGS(n)) \
87-
{ \
88-
if(!LogAcceptCategory(category)) return 0; \
89-
return LogPrintStr(tfm::format(format, TINYFORMAT_PASSARGS(n))); \
90-
} \
91-
/** Log error and return false */ \
92-
template<TINYFORMAT_ARGTYPES(n)> \
93-
static inline bool error(const char* format, TINYFORMAT_VARARGS(n)) \
94-
{ \
95-
LogPrintStr("ERROR: " + tfm::format(format, TINYFORMAT_PASSARGS(n)) + "\n"); \
96-
return false; \
97-
}
79+
template<typename T1, typename... Args>
80+
static inline int LogPrint(const char* category, const char* fmt, const T1& v1, const Args&... args)
81+
{
82+
if(!LogAcceptCategory(category)) return 0; \
83+
return LogPrintStr(tfm::format(fmt, v1, args...));
84+
}
9885

99-
TINYFORMAT_FOREACH_ARGNUM(MAKE_ERROR_AND_LOG_FUNC)
86+
template<typename T1, typename... Args>
87+
bool error(const char* fmt, const T1& v1, const Args&... args)
88+
{
89+
LogPrintStr("ERROR: " + tfm::format(fmt, v1, args...) + "\n");
90+
return false;
91+
}
10092

10193
/**
10294
* Zero-arg versions of logging and error, these are not covered by
103-
* TINYFORMAT_FOREACH_ARGNUM
95+
* the variadic templates above (and don't take format arguments but
96+
* bare strings).
10497
*/
105-
static inline int LogPrint(const char* category, const char* format)
98+
static inline int LogPrint(const char* category, const char* s)
10699
{
107100
if(!LogAcceptCategory(category)) return 0;
108-
return LogPrintStr(format);
101+
return LogPrintStr(s);
109102
}
110-
static inline bool error(const char* format)
103+
static inline bool error(const char* s)
111104
{
112-
LogPrintStr(std::string("ERROR: ") + format + "\n");
105+
LogPrintStr(std::string("ERROR: ") + s + "\n");
113106
return false;
114107
}
115108

0 commit comments

Comments
 (0)