Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed May 16, 2024
1 parent 0b5287f commit 75e8924
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -4000,8 +4000,7 @@ struct formatter<T, Char, enable_if_t<detail::has_format_as<T>::value>>
template <typename FormatContext>
auto format(const T& value, FormatContext& ctx) const -> decltype(ctx.out()) {
using base = formatter<detail::format_as_t<T>, Char>;
// format functions expect lvalue refs, not rvalues
auto&& val = format_as(value);
auto&& val = format_as(value); // Make an lvalue reference for format.
return base::format(val, ctx);
}
};
Expand Down
16 changes: 8 additions & 8 deletions test/ranges-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,13 @@ TEST(ranges_test, input_range_join_overload) {

namespace views_filter_view_test {
struct codec_mask {
static constexpr auto kCodecs = std::array{0, 1, 2, 3};
int except{};
static constexpr auto codecs = std::array{0, 1, 2, 3};
int except = 0;
};

auto format_as(codec_mask mask) {
// Careful not to capture param by reference here, it will dangle
return codec_mask::kCodecs |
// Careful not to capture param by reference here, it will dangle.
return codec_mask::codecs |
std::views::filter([mask](auto c) { return c != mask.except; });
}
} // namespace views_filter_view_test
Expand All @@ -698,7 +698,7 @@ TEST(ranges_test, format_as_with_ranges_mutable_begin_end) {
using namespace views_filter_view_test;
{
auto make_filter_view = []() {
return codec_mask::kCodecs |
return codec_mask::codecs |
std::views::filter([](auto c) { return c != 2; });
};
auto r = make_filter_view();
Expand All @@ -707,11 +707,11 @@ TEST(ranges_test, format_as_with_ranges_mutable_begin_end) {
}

{
const codec_mask const_mask{2};
codec_mask mask{2};
auto mask = codec_mask{2};
const auto const_mask = codec_mask{2};

EXPECT_EQ("[0, 1, 3]", fmt::format("{}", const_mask));
EXPECT_EQ("[0, 1, 3]", fmt::format("{}", mask));
EXPECT_EQ("[0, 1, 3]", fmt::format("{}", const_mask));
EXPECT_EQ("[0, 1, 3]", fmt::format("{}", codec_mask{2}));
}
}
Expand Down

0 comments on commit 75e8924

Please sign in to comment.