mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Optimize copy_str for counting_iterator
This commit is contained in:
@ -443,13 +443,17 @@ class counting_iterator {
|
|||||||
++count_;
|
++count_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
counting_iterator operator++(int) {
|
counting_iterator operator++(int) {
|
||||||
auto it = *this;
|
auto it = *this;
|
||||||
++*this;
|
++*this;
|
||||||
return it;
|
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 {}; }
|
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); });
|
[](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
|
#ifndef FMT_USE_GRISU
|
||||||
# define FMT_USE_GRISU 1
|
# define FMT_USE_GRISU 1
|
||||||
#endif
|
#endif
|
||||||
|
@ -147,6 +147,7 @@ TEST(IteratorTest, CountingIterator) {
|
|||||||
auto prev = it++;
|
auto prev = it++;
|
||||||
EXPECT_EQ(prev.count(), 0);
|
EXPECT_EQ(prev.count(), 0);
|
||||||
EXPECT_EQ(it.count(), 1);
|
EXPECT_EQ(it.count(), 1);
|
||||||
|
EXPECT_EQ((it + 41).count(), 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(IteratorTest, TruncatingIterator) {
|
TEST(IteratorTest, TruncatingIterator) {
|
||||||
|
Reference in New Issue
Block a user