Skip to content

Commit 3691548

Browse files
committed
Remove counting_iterator
1 parent f6b4a23 commit 3691548

File tree

4 files changed

+8
-57
lines changed

4 files changed

+8
-57
lines changed

Diff for: include/fmt/base.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ template <typename T = char> class counting_buffer : public buffer<T> {
11031103
}
11041104

11051105
public:
1106-
counting_buffer() : buffer<T>(grow, data_, 0, buffer_size) {}
1106+
FMT_CONSTEXPR counting_buffer() : buffer<T>(grow, data_, 0, buffer_size) {}
11071107

11081108
auto count() -> size_t { return count_ + this->size(); }
11091109
};

Diff for: include/fmt/compile.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ FMT_EXPORT class compiled_string {};
2121

2222
namespace detail {
2323

24-
template <typename T, typename InputIt>
25-
FMT_CONSTEXPR inline auto copy(InputIt begin, InputIt end, counting_iterator it)
26-
-> counting_iterator {
27-
return it + (end - begin);
28-
}
29-
3024
template <typename S>
3125
struct is_compiled_string : std::is_base_of<compiled_string, S> {};
3226

@@ -496,7 +490,8 @@ template <typename S, typename... Args,
496490
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
497491
auto formatted_size(const S& fmt, const Args&... args) -> size_t {
498492
auto buf = detail::counting_buffer<>();
499-
return fmt::format_to(fmt::appender(buf), fmt, args...).count();
493+
fmt::format_to(appender(buf), fmt, args...);
494+
return buf.count();
500495
}
501496

502497
template <typename S, typename... Args,

Diff for: include/fmt/format.h

+5-41
Original file line numberDiff line numberDiff line change
@@ -2235,46 +2235,6 @@ FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value,
22352235
loc);
22362236
}
22372237

2238-
// An output iterator that counts the number of objects written to it and
2239-
// discards them.
2240-
class counting_iterator {
2241-
private:
2242-
size_t count_;
2243-
2244-
public:
2245-
using iterator_category = std::output_iterator_tag;
2246-
using difference_type = std::ptrdiff_t;
2247-
using pointer = void;
2248-
using reference = void;
2249-
FMT_UNCHECKED_ITERATOR(counting_iterator);
2250-
2251-
struct value_type {
2252-
template <typename T> FMT_CONSTEXPR void operator=(const T&) {}
2253-
};
2254-
2255-
FMT_CONSTEXPR counting_iterator() : count_(0) {}
2256-
2257-
FMT_CONSTEXPR auto count() const -> size_t { return count_; }
2258-
2259-
FMT_CONSTEXPR auto operator++() -> counting_iterator& {
2260-
++count_;
2261-
return *this;
2262-
}
2263-
FMT_CONSTEXPR auto operator++(int) -> counting_iterator {
2264-
auto it = *this;
2265-
++*this;
2266-
return it;
2267-
}
2268-
2269-
FMT_CONSTEXPR friend auto operator+(counting_iterator it, difference_type n)
2270-
-> counting_iterator {
2271-
it.count_ += static_cast<size_t>(n);
2272-
return it;
2273-
}
2274-
2275-
FMT_CONSTEXPR auto operator*() const -> value_type { return {}; }
2276-
};
2277-
22782238
template <typename Char, typename OutputIt>
22792239
FMT_CONSTEXPR auto write(OutputIt out, basic_string_view<Char> s,
22802240
const format_specs& specs) -> OutputIt {
@@ -2285,7 +2245,11 @@ FMT_CONSTEXPR auto write(OutputIt out, basic_string_view<Char> s,
22852245
bool is_debug = specs.type == presentation_type::debug;
22862246
size_t width = 0;
22872247

2288-
if (is_debug) size = write_escaped_string(counting_iterator{}, s).count();
2248+
if (is_debug) {
2249+
auto buf = counting_buffer<>();
2250+
write_escaped_string(appender(buf), s);
2251+
size = buf.count();
2252+
}
22892253

22902254
if (specs.width != 0) {
22912255
if (is_debug)

Diff for: test/compile-test.cc

-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
#include "gmock/gmock.h"
1515
#include "gtest-extra.h"
1616

17-
TEST(iterator_test, counting_iterator) {
18-
auto it = fmt::detail::counting_iterator();
19-
auto prev = it++;
20-
EXPECT_EQ(prev.count(), 0);
21-
EXPECT_EQ(it.count(), 1);
22-
EXPECT_EQ((it + 41).count(), 42);
23-
}
24-
2517
TEST(compile_test, compile_fallback) {
2618
// FMT_COMPILE should fallback on runtime formatting when `if constexpr` is
2719
// not available.

0 commit comments

Comments
 (0)