Supporting ? as a string presentation type (#2674)

* Supporting ? as a string presentation type.

* Supporting ? as a char presentation type.

* Adding iterator_category to counting_iterator.
This commit is contained in:
Barry Revzin
2022-01-30 08:55:28 -08:00
committed by GitHub
parent ae1aaaee5f
commit a34a97cc1d
7 changed files with 421 additions and 354 deletions
-39
View File
@@ -13,45 +13,6 @@
FMT_BEGIN_NAMESPACE
namespace detail {
// An output iterator that counts the number of objects written to it and
// discards them.
class counting_iterator {
private:
size_t count_;
public:
using iterator_category = std::output_iterator_tag;
using difference_type = std::ptrdiff_t;
using pointer = void;
using reference = void;
using _Unchecked_type = counting_iterator; // Mark iterator as checked.
struct value_type {
template <typename T> void operator=(const T&) {}
};
counting_iterator() : count_(0) {}
size_t count() const { return count_; }
counting_iterator& operator++() {
++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 {}; }
};
template <typename Char, typename InputIt>
inline counting_iterator copy_str(InputIt begin, InputIt end,
counting_iterator it) {