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
2fe94ad7
Commit
2fe94ad7
authored
Sep 05, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make specifiers support in tuple_join an opt-in
parent
3940de59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
include/fmt/ranges.h
include/fmt/ranges.h
+9
-0
test/ranges-test.cc
test/ranges-test.cc
+2
-0
No files found.
include/fmt/ranges.h
View file @
2fe94ad7
...
...
@@ -625,6 +625,13 @@ template <typename Char, typename... T> struct tuple_join_view : detail::view {
template
<
typename
Char
,
typename
...
T
>
using
tuple_arg_join
=
tuple_join_view
<
Char
,
T
...
>
;
// Define FMT_TUPLE_JOIN_SPECIFIERS to enable experimental format specifiers
// support in tuple_join. It is disabled by default because of issues with
// the dynamic width and precision.
#ifndef FMT_TUPLE_JOIN_SPECIFIERS
# define FMT_TUPLE_JOIN_SPECIFIERS 0
#endif
template
<
typename
Char
,
typename
...
T
>
struct
formatter
<
tuple_join_view
<
Char
,
T
...
>
,
Char
>
{
template
<
typename
ParseContext
>
...
...
@@ -654,11 +661,13 @@ struct formatter<tuple_join_view<Char, T...>, Char> {
std
::
integral_constant
<
size_t
,
N
>
)
->
decltype
(
ctx
.
begin
())
{
auto
end
=
std
::
get
<
sizeof
...(
T
)
-
N
>
(
formatters_
).
parse
(
ctx
);
#if FMT_TUPLE_JOIN_SPECIFIERS
if
(
N
>
1
)
{
auto
end1
=
do_parse
(
ctx
,
std
::
integral_constant
<
size_t
,
N
-
1
>
());
if
(
end
!=
end1
)
FMT_THROW
(
format_error
(
"incompatible format specs for tuple elements"
));
}
#endif
return
end
;
}
...
...
test/ranges-test.cc
View file @
2fe94ad7
...
...
@@ -225,6 +225,7 @@ TEST(ranges_test, join_tuple) {
auto
t4
=
std
::
tuple
<
float
>
(
4.0
f
);
EXPECT_EQ
(
fmt
::
format
(
"{}"
,
fmt
::
join
(
t4
,
"/"
)),
"4"
);
# if FMT_TUPLE_JOIN_SPECIFIERS
// Specs applied to each element.
auto
t5
=
std
::
tuple
<
int
,
int
,
long
>
(
-
3
,
100
,
1
);
EXPECT_EQ
(
fmt
::
format
(
"{:+03}"
,
fmt
::
join
(
t5
,
", "
)),
"-03, +100, +01"
);
...
...
@@ -237,6 +238,7 @@ TEST(ranges_test, join_tuple) {
int
y
=
-
1
;
auto
t7
=
std
::
tuple
<
int
,
int
&
,
const
int
&>
(
3
,
y
,
y
);
EXPECT_EQ
(
fmt
::
format
(
"{:03}"
,
fmt
::
join
(
t7
,
", "
)),
"003, -01, -01"
);
# endif
}
TEST
(
ranges_test
,
join_initializer_list
)
{
...
...
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