mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-27 21:31:20 +00:00
Optimize copy_str for counting_iterator
This commit is contained in:
parent
2591ab91c3
commit
16410056bf
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user