Fixing buffer_appender's ++ slicing.
This commit is contained in:
parent
76e97dc4df
commit
5a480de205
@ -845,11 +845,23 @@ template <typename T = char> class counting_buffer : public buffer<T> {
|
|||||||
// It is used to reduce symbol sizes for the common case.
|
// It is used to reduce symbol sizes for the common case.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class buffer_appender : public std::back_insert_iterator<buffer<T>> {
|
class buffer_appender : public std::back_insert_iterator<buffer<T>> {
|
||||||
|
using base = std::back_insert_iterator<buffer<T>>;
|
||||||
public:
|
public:
|
||||||
explicit buffer_appender(buffer<T>& buf)
|
explicit buffer_appender(buffer<T>& buf)
|
||||||
: std::back_insert_iterator<buffer<T>>(buf) {}
|
: base(buf) {}
|
||||||
buffer_appender(std::back_insert_iterator<buffer<T>> it)
|
buffer_appender(base it)
|
||||||
: std::back_insert_iterator<buffer<T>>(it) {}
|
: base(it) {}
|
||||||
|
|
||||||
|
buffer_appender& operator++() {
|
||||||
|
base::operator++();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_appender operator++(int) {
|
||||||
|
buffer_appender tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Maps an output iterator into a buffer.
|
// Maps an output iterator into a buffer.
|
||||||
|
|||||||
@ -2473,3 +2473,29 @@ TEST(FormatTest, FormatUTF8Precision) {
|
|||||||
EXPECT_EQ(result.size(), 5);
|
EXPECT_EQ(result.size(), 5);
|
||||||
EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5)));
|
EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct lazy_optional {
|
||||||
|
bool engaged;
|
||||||
|
std::string value;
|
||||||
|
};
|
||||||
|
|
||||||
|
FMT_BEGIN_NAMESPACE
|
||||||
|
template <> struct formatter<lazy_optional> : formatter<std::string_view> {
|
||||||
|
template <typename Context>
|
||||||
|
auto format(const lazy_optional& opt, Context& ctx) {
|
||||||
|
if (opt.engaged) {
|
||||||
|
auto out = format_to(ctx.out(), "Some(");
|
||||||
|
out = format_to(out, "{}", opt.value);
|
||||||
|
*out = ')';
|
||||||
|
return ++out;
|
||||||
|
} else {
|
||||||
|
return format_to(ctx.out(), "None()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
|
TEST(FormatTest, BackInsertSlicing) {
|
||||||
|
EXPECT_EQ(fmt::format("{}", lazy_optional{false, ""}), "None()");
|
||||||
|
EXPECT_EQ(fmt::format("{}", lazy_optional{true, "X"}), "Some(X)");
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user