Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
4f4e6c96
Commit
4f4e6c96
authored
Jun 28, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MSVC build. FormatError -> FormatMessage to avoid ambiguity.
parent
5aa36285
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
14 deletions
+15
-14
format.h
format.h
+8
-7
test/format-test.cc
test/format-test.cc
+7
-7
No files found.
format.h
View file @
4f4e6c96
...
...
@@ -2184,7 +2184,8 @@ inline void FormatDec(char *&buffer, T value) {
#define FMT_RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define FMT_CONCAT(a, b) a##b
#define FMT_FOR_EACH_(N, f, ...) FMT_CONCAT(FMT_FOR_EACH, N)(f, __VA_ARGS__)
#define FMT_FOR_EACH_(N, f, ...) \
FMT_EXPAND(FMT_CONCAT(FMT_FOR_EACH, N)(f, __VA_ARGS__))
#define FMT_FOR_EACH(f, ...) \
FMT_EXPAND(FMT_FOR_EACH_(FMT_NARG(__VA_ARGS__), f, __VA_ARGS__))
...
...
@@ -2194,26 +2195,26 @@ inline void FormatDec(char *&buffer, T value) {
// Defines a wrapper for a function taking __VA_ARGS__ arguments
// and n additional arguments of arbitrary types.
# define FMT_WRAP(return_type, func, n, ...)
FMT_EXPAND(
\
# define FMT_WRAP(return_type, func, n, ...) \
template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \
inline return_type func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
FMT_GEN(n, FMT_MAKE_ARG)) { \
const fmt::internal::ArgInfo args[] = {FMT_GEN(n, FMT_MAKE_REF)}; \
return func(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \
fmt::ArgList(args, sizeof(args) / sizeof(*args))); \
}
)
}
// Defines a variadic function with the specified return type and argument
// types passed as variable arguments.
// Example:
// std::string Format
Error(int error_code, const char *format
,
// const fmt::ArgList &args) {
// std::string Format
Message(const char *format, int id
,
//
const fmt::ArgList &args) {
// fmt::Writer w;
// w.format("
Error {}: ", error_code
);
// w.format("
[{}] ", id
);
// w.format(format, args);
// return w.str();
// }
// FMT_VARIADIC(std::string, Format
Error
, int, const char *)
// FMT_VARIADIC(std::string, Format
Message
, int, const char *)
#define FMT_VARIADIC(return_type, func, ...) \
inline return_type func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__)) { \
return func(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \
...
...
test/format-test.cc
View file @
4f4e6c96
...
...
@@ -1677,17 +1677,17 @@ TEST(FormatTest, VariadicMacro) {
EXPECT_EQ
(
"42 abc 1.2"
,
test
(
42
,
" {} {}"
,
"abc"
,
1.2
));
}
std
::
string
Format
Error
(
int
error_code
,
const
char
*
format
,
std
::
string
Format
Message
(
const
char
*
format
,
int
id
,
const
fmt
::
ArgList
&
args
)
{
fmt
::
Writer
w
;
w
.
format
(
"
Error {}: "
,
error_code
);
w
.
format
(
"
[{}] "
,
id
);
w
.
format
(
format
,
args
);
return
w
.
str
();
}
FMT_VARIADIC
(
std
::
string
,
Format
Error
,
int
,
const
char
*
)
FMT_VARIADIC
(
std
::
string
,
Format
Message
,
int
,
const
char
*
)
TEST
(
FormatTest
,
FormatError
)
{
EXPECT_EQ
(
"Error 42: something happened"
,
FormatError
(
42
,
"{} happened"
,
"something"
));
}
\ No newline at end of file
TEST
(
FormatTest
,
FormatMessageExample
)
{
EXPECT_EQ
(
"[42] something happened"
,
MyFormatError
(
42
,
"{} happened"
,
"something"
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment