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
9c0c1bcd
Commit
9c0c1bcd
authored
Dec 29, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify tuple formatting
parent
187e8db1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
26 deletions
+10
-26
include/fmt/ranges.h
include/fmt/ranges.h
+10
-26
No files found.
include/fmt/ranges.h
View file @
9c0c1bcd
...
...
@@ -13,22 +13,13 @@
#define FMT_RANGES_H_
#include <initializer_list>
#include <tuple>
#include <type_traits>
#include "format.h"
FMT_BEGIN_NAMESPACE
template
<
typename
Char
,
typename
Enable
=
void
>
struct
formatting_tuple
{
Char
prefix
=
'('
;
Char
postfix
=
')'
;
template
<
typename
ParseContext
>
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
return
ctx
.
begin
();
}
};
namespace
detail
{
template
<
typename
RangeT
,
typename
OutputIterator
>
...
...
@@ -176,7 +167,7 @@ struct is_range_<T, void>
# undef FMT_DECLTYPE_RETURN
#endif
//
/
tuple_size and tuple_element check.
// tuple_size and tuple_element check.
template
<
typename
T
>
class
is_tuple_like_
{
template
<
typename
U
>
static
auto
check
(
U
*
p
)
->
decltype
(
std
::
tuple_size
<
U
>::
value
,
int
());
...
...
@@ -556,37 +547,30 @@ template <typename T> struct is_tuple_like {
template
<
typename
TupleT
,
typename
Char
>
struct
formatter
<
TupleT
,
Char
,
enable_if_t
<
fmt
::
is_tuple_like
<
TupleT
>::
value
>>
{
private:
// C++11 generic lambda for format()
// C++11 generic lambda for format()
.
template
<
typename
FormatContext
>
struct
format_each
{
template
<
typename
T
>
void
operator
()(
const
T
&
v
)
{
if
(
i
>
0
)
out
=
detail
::
write_delimiter
(
out
);
out
=
detail
::
write_range_entry
<
Char
>
(
out
,
v
);
++
i
;
}
formatting_tuple
<
Char
>&
formatting
;
size_t
&
i
;
typename
std
::
add_lvalue_reference
<
decltype
(
std
::
declval
<
FormatContext
>
().
out
())
>::
type
out
;
int
i
;
typename
FormatContext
::
iterator
&
out
;
};
public:
formatting_tuple
<
Char
>
formatting
;
template
<
typename
ParseContext
>
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
return
formatting
.
parse
(
ctx
);
return
ctx
.
begin
(
);
}
template
<
typename
FormatContext
=
format_context
>
auto
format
(
const
TupleT
&
values
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
auto
out
=
ctx
.
out
();
size_t
i
=
0
;
detail
::
copy
(
formatting
.
prefix
,
out
);
detail
::
for_each
(
values
,
format_each
<
FormatContext
>
{
formatting
,
i
,
out
});
detail
::
copy
(
formatting
.
postfix
,
out
);
return
ctx
.
out
();
*
out
++
=
'('
;
detail
::
for_each
(
values
,
format_each
<
FormatContext
>
{
0
,
out
});
*
out
++
=
')'
;
return
out
;
}
};
...
...
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