Skip to content
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

fmt::join support FMT_COMPILE #2720

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2818,8 +2818,8 @@ struct formatter<join_view<It, Sentinel, Char>, Char> {
}

template <typename FormatContext>
auto format(const join_view<It, Sentinel, Char>& value, FormatContext& ctx)
-> decltype(ctx.out()) {
auto format(const join_view<It, Sentinel, Char>& value,
FormatContext& ctx) const -> decltype(ctx.out()) {
auto it = value.begin;
auto out = ctx.out();
if (it != value.end) {
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
using formatter<basic_string_view<Char>, Char>::parse;

template <typename OutputIt>
auto format(const T& value, basic_format_context<OutputIt, Char>& ctx)
auto format(const T& value, basic_format_context<OutputIt, Char>& ctx) const
-> OutputIt {
auto buffer = basic_memory_buffer<Char>();
format_value(buffer, value, ctx.locale());
Expand All @@ -96,7 +96,7 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>

// DEPRECATED!
template <typename OutputIt>
auto format(const T& value, basic_printf_context<OutputIt, Char>& ctx)
auto format(const T& value, basic_printf_context<OutputIt, Char>& ctx) const
-> OutputIt {
auto buffer = basic_memory_buffer<Char>();
format_value(buffer, value, ctx.locale());
Expand Down
5 changes: 5 additions & 0 deletions test/compile-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ TEST(compile_test, named) {
# endif
}

TEST(compile_test, join) {
unsigned char data[] = {0x1, 0x2, 0xaf};
EXPECT_EQ("0102af", fmt::format(FMT_COMPILE("{:02x}"), fmt::join(data, "")));
}

TEST(compile_test, format_to) {
char buf[8];
auto end = fmt::format_to(buf, FMT_COMPILE("{}"), 42);
Expand Down