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
16410056
Commit
16410056
authored
Sep 22, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize copy_str for counting_iterator
parent
2591ab91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
include/fmt/format.h
include/fmt/format.h
+11
-1
test/format-test.cc
test/format-test.cc
+1
-0
No files found.
include/fmt/format.h
View file @
16410056
...
...
@@ -443,13 +443,17 @@ class counting_iterator {
++
count_
;
return
*
this
;
}
counting_iterator
operator
++
(
int
)
{
auto
it
=
*
this
;
++*
this
;
return
it
;
}
friend
counting_iterator
operator
+
(
counting_iterator
it
,
difference_type
n
)
{
it
.
count_
+=
static_cast
<
size_t
>
(
n
);
return
it
;
}
value_type
operator
*
()
const
{
return
{};
}
};
...
...
@@ -583,6 +587,12 @@ OutputIt copy_str(InputIt begin, InputIt end, OutputIt it) {
[](
char
c
)
{
return
static_cast
<
char8_type
>
(
c
);
});
}
template
<
typename
Char
,
typename
InputIt
>
inline
counting_iterator
copy_str
(
InputIt
begin
,
InputIt
end
,
counting_iterator
it
)
{
return
it
+
(
end
-
begin
);
}
#ifndef FMT_USE_GRISU
# define FMT_USE_GRISU 1
#endif
...
...
test/format-test.cc
View file @
16410056
...
...
@@ -147,6 +147,7 @@ TEST(IteratorTest, CountingIterator) {
auto
prev
=
it
++
;
EXPECT_EQ
(
prev
.
count
(),
0
);
EXPECT_EQ
(
it
.
count
(),
1
);
EXPECT_EQ
((
it
+
41
).
count
(),
42
);
}
TEST
(
IteratorTest
,
TruncatingIterator
)
{
...
...
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