diff --git a/include/fmt/format.h b/include/fmt/format.h index fe2a140b..71a331e3 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -840,7 +840,11 @@ class counting_iterator { return *this; } - counting_iterator operator++(int) { return ++*this; } + counting_iterator operator++(int) { + auto it = *this; + ++*this; + return it; + } T &operator*() const { return blackhole_; } }; @@ -877,7 +881,11 @@ class truncating_iterator { return *this; } - truncating_iterator operator++(int) { return ++*this; } + truncating_iterator operator++(int) { + auto it = *this; + ++*this; + return it; + } reference operator*() const { return count_ < limit_ ? *out_ : blackhole_; } }; diff --git a/test/format-test.cc b/test/format-test.cc index 769e5718..e0cddd14 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -14,16 +14,11 @@ #include #include -#include "gmock.h" - -// Test that the library compiles if None is defined to 0 as done by xlib.h. -#define None 0 - #include "fmt/format.h" - -#include "util.h" -#include "mock-allocator.h" +#include "gmock.h" #include "gtest-extra.h" +#include "mock-allocator.h" +#include "util.h" #undef min #undef max @@ -1528,9 +1523,6 @@ TEST(FormatTest, FormatToN) { EXPECT_EQ(6u, result.size); EXPECT_EQ(buffer + 3, result.out); EXPECT_EQ("foox", fmt::string_view(buffer, 4)); - - // Workaround for potentially unused macro - static_cast(None); } #if FMT_USE_CONSTEXPR diff --git a/test/util-test.cc b/test/util-test.cc index c4c7f44a..e14878f4 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -931,3 +931,18 @@ TEST(FPTest, GetCachedPower) { EXPECT_DOUBLE_EQ(pow(10, dec_exp), ldexp(fp.f, fp.e)); } } + +TEST(IteratorTest, CountingIterator) { + fmt::internal::counting_iterator it; + auto prev = it++; + EXPECT_EQ(prev.count(), 0); + EXPECT_EQ(it.count(), 1); +} + +TEST(IteratorTest, TruncatingIterator) { + char *p = FMT_NULL; + fmt::internal::truncating_iterator it(p, 3); + auto prev = it++; + EXPECT_EQ(prev.base(), p); + EXPECT_EQ(it.base(), p + 1); +}