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
9e3f3e8c
Commit
9e3f3e8c
authored
Jan 05, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of output iterators in format_to_n (#1506)
parent
aa07c576
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
8 deletions
+32
-8
include/fmt/format.h
include/fmt/format.h
+5
-8
test/format-test.cc
test/format-test.cc
+27
-0
No files found.
include/fmt/format.h
View file @
9e3f3e8c
...
...
@@ -395,6 +395,7 @@ template <typename OutputIt> class truncating_iterator_base {
public:
using
iterator_category
=
std
::
output_iterator_tag
;
using
value_type
=
typename
std
::
iterator_traits
<
OutputIt
>::
value_type
;
using
difference_type
=
void
;
using
pointer
=
void
;
using
reference
=
void
;
...
...
@@ -415,12 +416,10 @@ class truncating_iterator;
template
<
typename
OutputIt
>
class
truncating_iterator
<
OutputIt
,
std
::
false_type
>
:
public
truncating_iterator_base
<
OutputIt
>
{
using
traits
=
std
::
iterator_traits
<
OutputIt
>
;
mutable
typename
traits
::
value_type
blackhole_
;
mutable
typename
truncating_iterator_base
<
OutputIt
>::
value_type
blackhole_
;
public:
using
value_type
=
typename
tr
aits
::
value_type
;
using
value_type
=
typename
tr
uncating_iterator_base
<
OutputIt
>
::
value_type
;
truncating_iterator
(
OutputIt
out
,
std
::
size_t
limit
)
:
truncating_iterator_base
<
OutputIt
>
(
out
,
limit
)
{}
...
...
@@ -445,13 +444,11 @@ template <typename OutputIt>
class
truncating_iterator
<
OutputIt
,
std
::
true_type
>
:
public
truncating_iterator_base
<
OutputIt
>
{
public:
using
value_type
=
typename
OutputIt
::
container_type
::
value_type
;
truncating_iterator
(
OutputIt
out
,
std
::
size_t
limit
)
:
truncating_iterator_base
<
OutputIt
>
(
out
,
limit
)
{}
t
runcating_iterator
&
operator
=
(
value_type
val
)
{
if
(
this
->
count_
++
<
this
->
limit_
)
this
->
out_
=
val
;
t
emplate
<
typename
T
>
truncating_iterator
&
operator
=
(
T
val
)
{
if
(
this
->
count_
++
<
this
->
limit_
)
*
this
->
out_
++
=
val
;
return
*
this
;
}
...
...
test/format-test.cc
View file @
9e3f3e8c
...
...
@@ -2080,6 +2080,33 @@ TEST(FormatTest, WideFormatToN) {
EXPECT_EQ
(
L"BC x"
,
fmt
::
wstring_view
(
buffer
,
4
));
}
struct
test_output_iterator
{
char
*
data
;
using
iterator_category
=
std
::
output_iterator_tag
;
using
value_type
=
void
;
using
difference_type
=
void
;
using
pointer
=
void
;
using
reference
=
void
;
test_output_iterator
&
operator
++
()
{
++
data
;
return
*
this
;
}
test_output_iterator
operator
++
(
int
)
{
auto
tmp
=
*
this
;
++
data
;
return
tmp
;
}
char
&
operator
*
()
{
return
*
data
;
}
};
TEST
(
FormatTest
,
FormatToNOutputIterator
)
{
char
buf
[
10
]
=
{};
fmt
::
format_to_n
(
test_output_iterator
{
buf
},
10
,
"{}"
,
42
);
EXPECT_STREQ
(
buf
,
"42"
);
}
#if FMT_USE_CONSTEXPR
struct
test_arg_id_handler
{
enum
result
{
NONE
,
EMPTY
,
INDEX
,
NAME
,
ERROR
};
...
...
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