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
9a4cc884
Commit
9a4cc884
authored
Jun 20, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add FMT_COMPILE support to format_to
parent
5ddf9ee1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
include/fmt/compile.h
include/fmt/compile.h
+12
-2
test/compile-test.cc
test/compile-test.cc
+7
-0
No files found.
include/fmt/compile.h
View file @
9a4cc884
...
...
@@ -24,7 +24,9 @@ struct is_compiled_string : std::is_base_of<compiled_string, S> {};
#define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string)
template
<
typename
T
,
typename
...
Tail
>
const
T
&
first
(
const
T
&
value
,
const
Tail
&
...)
{
return
value
;
}
const
T
&
first
(
const
T
&
value
,
const
Tail
&
...)
{
return
value
;
}
// Part of a compiled format string. It can be either literal text or a
// replacement field.
...
...
@@ -556,7 +558,8 @@ std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
template
<
typename
S
,
typename
...
Args
,
FMT_ENABLE_IF
(
detail
::
is_compiled_string
<
S
>
::
value
)
>
FMT_INLINE
std
::
basic_string
<
typename
S
::
char_type
>
format
(
S
,
Args
&&
...
args
)
{
FMT_INLINE
std
::
basic_string
<
typename
S
::
char_type
>
format
(
const
S
&
,
Args
&&
...
args
)
{
constexpr
basic_string_view
<
typename
S
::
char_type
>
str
=
S
();
if
(
str
.
size
()
==
2
&&
str
[
0
]
==
'{'
&&
str
[
1
]
==
'}'
)
return
fmt
::
to_string
(
detail
::
first
(
args
...));
...
...
@@ -575,6 +578,13 @@ OutputIt format_to(OutputIt out, const CompiledFormat& cf,
make_format_args
<
context
>
(
args
...));
}
template
<
typename
OutputIt
,
typename
S
,
typename
...
Args
,
FMT_ENABLE_IF
(
detail
::
is_compiled_string
<
S
>
::
value
)
>
OutputIt
format_to
(
OutputIt
out
,
const
S
&
,
const
Args
&
...
args
)
{
constexpr
auto
compiled
=
compile
<
Args
...
>
(
S
());
return
format_to
(
out
,
compiled
,
args
...);
}
template
<
typename
OutputIt
,
typename
CompiledFormat
,
typename
...
Args
,
FMT_ENABLE_IF
(
detail
::
is_output_iterator
<
OutputIt
>
::
value
&&
std
::
is_base_of
<
...
...
test/compile-test.cc
View file @
9a4cc884
...
...
@@ -156,6 +156,13 @@ TEST(CompileTest, FormatDefault) {
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
FMT_COMPILE
(
"{}"
),
std
::
string
(
"foo"
)));
}
TEST
(
CompileTest
,
FormatTo
)
{
char
buf
[
8
];
auto
end
=
fmt
::
format_to
(
buf
,
FMT_COMPILE
(
"{}"
),
42
);
*
end
=
'\0'
;
EXPECT_STREQ
(
"42"
,
buf
);
}
TEST
(
CompileTest
,
TextAndArg
)
{
EXPECT_EQ
(
">>>42<<<"
,
fmt
::
format
(
FMT_COMPILE
(
">>>{}<<<"
),
42
));
}
...
...
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