mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-11 09:40:48 +00:00
Remove counting_iterator
This commit is contained in:
parent
f6b4a23b83
commit
ba36a04811
@ -1103,7 +1103,7 @@ template <typename T = char> class counting_buffer : public buffer<T> {
|
||||
}
|
||||
|
||||
public:
|
||||
counting_buffer() : buffer<T>(grow, data_, 0, buffer_size) {}
|
||||
FMT_CONSTEXPR counting_buffer() : buffer<T>(grow, data_, 0, buffer_size) {}
|
||||
|
||||
auto count() -> size_t { return count_ + this->size(); }
|
||||
};
|
||||
|
@ -21,12 +21,6 @@ FMT_EXPORT class compiled_string {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T, typename InputIt>
|
||||
FMT_CONSTEXPR inline auto copy(InputIt begin, InputIt end, counting_iterator it)
|
||||
-> counting_iterator {
|
||||
return it + (end - begin);
|
||||
}
|
||||
|
||||
template <typename S>
|
||||
struct is_compiled_string : std::is_base_of<compiled_string, S> {};
|
||||
|
||||
@ -496,7 +490,8 @@ template <typename S, typename... Args,
|
||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||
auto formatted_size(const S& fmt, const Args&... args) -> size_t {
|
||||
auto buf = detail::counting_buffer<>();
|
||||
return fmt::format_to(fmt::appender(buf), fmt, args...).count();
|
||||
fmt::format_to(appender(buf), fmt, args...);
|
||||
return buf.count();
|
||||
}
|
||||
|
||||
template <typename S, typename... Args,
|
||||
|
@ -2235,46 +2235,6 @@ FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value,
|
||||
loc);
|
||||
}
|
||||
|
||||
// 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;
|
||||
FMT_UNCHECKED_ITERATOR(counting_iterator);
|
||||
|
||||
struct value_type {
|
||||
template <typename T> FMT_CONSTEXPR void operator=(const T&) {}
|
||||
};
|
||||
|
||||
FMT_CONSTEXPR counting_iterator() : count_(0) {}
|
||||
|
||||
FMT_CONSTEXPR auto count() const -> size_t { return count_; }
|
||||
|
||||
FMT_CONSTEXPR auto operator++() -> counting_iterator& {
|
||||
++count_;
|
||||
return *this;
|
||||
}
|
||||
FMT_CONSTEXPR auto operator++(int) -> counting_iterator {
|
||||
auto it = *this;
|
||||
++*this;
|
||||
return it;
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR friend auto operator+(counting_iterator it, difference_type n)
|
||||
-> counting_iterator {
|
||||
it.count_ += static_cast<size_t>(n);
|
||||
return it;
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR auto operator*() const -> value_type { return {}; }
|
||||
};
|
||||
|
||||
template <typename Char, typename OutputIt>
|
||||
FMT_CONSTEXPR auto write(OutputIt out, basic_string_view<Char> s,
|
||||
const format_specs& specs) -> OutputIt {
|
||||
@ -2285,7 +2245,11 @@ FMT_CONSTEXPR auto write(OutputIt out, basic_string_view<Char> s,
|
||||
bool is_debug = specs.type == presentation_type::debug;
|
||||
size_t width = 0;
|
||||
|
||||
if (is_debug) size = write_escaped_string(counting_iterator{}, s).count();
|
||||
if (is_debug) {
|
||||
auto buf = counting_buffer<Char>();
|
||||
write_escaped_string(basic_appender<Char>(buf), s);
|
||||
size = buf.count();
|
||||
}
|
||||
|
||||
if (specs.width != 0) {
|
||||
if (is_debug)
|
||||
|
@ -14,14 +14,6 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest-extra.h"
|
||||
|
||||
TEST(iterator_test, counting_iterator) {
|
||||
auto it = fmt::detail::counting_iterator();
|
||||
auto prev = it++;
|
||||
EXPECT_EQ(prev.count(), 0);
|
||||
EXPECT_EQ(it.count(), 1);
|
||||
EXPECT_EQ((it + 41).count(), 42);
|
||||
}
|
||||
|
||||
TEST(compile_test, compile_fallback) {
|
||||
// FMT_COMPILE should fallback on runtime formatting when `if constexpr` is
|
||||
// not available.
|
||||
|
Loading…
x
Reference in New Issue
Block a user