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
7a9c1ba1
Commit
7a9c1ba1
authored
Oct 22, 2017
by
Ludek Vodicka
Committed by
Victor Zverovich
Oct 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FMT_VARIADIC_CONST - Support for const variadic methods (#591)
FMT_VARIADIC_CONST - Support for const variadic methods
parent
324415c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
23 deletions
+47
-23
fmt/format.h
fmt/format.h
+29
-23
test/format-test.cc
test/format-test.cc
+18
-0
No files found.
fmt/format.h
View file @
7a9c1ba1
...
...
@@ -3634,10 +3634,10 @@ void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
#define FMT_GET_ARG_NAME(type, index) arg##index
#if FMT_USE_VARIADIC_TEMPLATES
# define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \
# define FMT_VARIADIC_(C
onst, C
har, ReturnType, func, call, ...) \
template <typename... Args> \
ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
const Args & ... args) { \
const Args & ... args)
Const
{ \
typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
typename ArgArray::Type array{ \
ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
...
...
@@ -3647,35 +3647,35 @@ void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
#else
// Defines a wrapper for a function taking __VA_ARGS__ arguments
// and n additional arguments of arbitrary types.
# define FMT_WRAP(Char, ReturnType, func, call, n, ...) \
# define FMT_WRAP(C
onst, C
har, ReturnType, func, call, n, ...) \
template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \
inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
FMT_GEN(n, FMT_MAKE_ARG)) { \
FMT_GEN(n, FMT_MAKE_ARG))
Const
{ \
fmt::internal::ArgArray<n>::Type arr; \
FMT_GEN(n, FMT_ASSIGN_##Char); \
call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList( \
fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), arr)); \
}
# define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \
inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__)) { \
# define FMT_VARIADIC_(C
onst, C
har, ReturnType, func, call, ...) \
inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__))
Const
{ \
call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList()); \
} \
FMT_WRAP(Char, ReturnType, func, call, 1, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 2, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 3, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 4, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 5, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 6, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 7, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 8, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 9, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 10, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 11, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 12, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 13, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 14, __VA_ARGS__) \
FMT_WRAP(Char, ReturnType, func, call, 15, __VA_ARGS__)
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 1, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 2, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 3, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 4, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 5, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 6, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 7, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 8, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 9, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 10, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 11, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 12, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 13, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 14, __VA_ARGS__) \
FMT_WRAP(C
onst, C
har, ReturnType, func, call, 15, __VA_ARGS__)
#endif // FMT_USE_VARIADIC_TEMPLATES
/**
...
...
@@ -3706,10 +3706,16 @@ void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
\endrst
*/
#define FMT_VARIADIC(ReturnType, func, ...) \
FMT_VARIADIC_(char, ReturnType, func, return func, __VA_ARGS__)
FMT_VARIADIC_(, char, ReturnType, func, return func, __VA_ARGS__)
#define FMT_VARIADIC_CONST(ReturnType, func, ...) \
FMT_VARIADIC_(const, char, ReturnType, func, return func, __VA_ARGS__)
#define FMT_VARIADIC_W(ReturnType, func, ...) \
FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__)
FMT_VARIADIC_(, wchar_t, ReturnType, func, return func, __VA_ARGS__)
#define FMT_VARIADIC_CONST_W(ReturnType, func, ...) \
FMT_VARIADIC_(const, wchar_t, ReturnType, func, return func, __VA_ARGS__)
#define FMT_CAPTURE_ARG_(id, index) ::fmt::arg(#id, id)
...
...
test/format-test.cc
View file @
7a9c1ba1
...
...
@@ -1630,6 +1630,24 @@ TEST(FormatTest, FormatMessageExample) {
format_message
(
42
,
"{} happened"
,
"something"
));
}
class
test_class
{
public:
std
::
string
format_message
(
int
id
,
const
char
*
format
,
const
fmt
::
ArgList
&
args
)
const
{
MemoryWriter
w
;
w
.
write
(
"[{}] "
,
id
);
w
.
write
(
format
,
args
);
return
w
.
str
();
}
FMT_VARIADIC_CONST
(
std
::
string
,
format_message
,
int
,
const
char
*
)
};
TEST
(
FormatTest
,
ConstFormatMessage
)
{
test_class
c
;
EXPECT_EQ
(
"[42] something happened"
,
c
.
format_message
(
42
,
"{} happened"
,
"something"
));
}
#if FMT_USE_VARIADIC_TEMPLATES
template
<
typename
...
Args
>
void
print_error
(
const
char
*
file
,
int
line
,
const
char
*
format
,
...
...
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