-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing buffer_appender's ++ slicing. #1822
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2473,3 +2473,37 @@ TEST(FormatTest, FormatUTF8Precision) { | |
EXPECT_EQ(result.size(), 5); | ||
EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5))); | ||
} | ||
|
||
#ifdef __cpp_decltype_auto | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make the test work without this, e.g. checking if the types are the same manually? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Just have a |
||
struct lazy_optional { | ||
bool engaged; | ||
std::string value; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd minimize this even further into an empty struct and make the name reflect what we are trying to test here. |
||
|
||
FMT_BEGIN_NAMESPACE | ||
template <> struct formatter<lazy_optional> { | ||
template <typename ParseContext> | ||
auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { | ||
return ctx.begin(); | ||
} | ||
|
||
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)"); | ||
} | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that
back_insert_iterator
only has like... 4 member functions, and I've already implemented 2 of them (and over-implemented them too, these could both just bereturn *this;
), maybe we should just implement the whole thing in here withoutstd
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine as is.