From 5e9dfa354c5cc6bc8c165cdc1ede174330a4fe68 Mon Sep 17 00:00:00 2001 From: Shawn Zhong Date: Tue, 7 Feb 2023 03:24:39 -0600 Subject: [PATCH] Make const-correct --- include/fmt/ranges.h | 4 ++-- test/ranges-test.cc | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 8e24aba2..fae425f9 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -678,9 +678,9 @@ struct formatter::value>> : formatter { template - auto format(T& t, FormatContext& ctx) const -> decltype(ctx.out()) { + auto format(const T& t, FormatContext& ctx) const -> decltype(ctx.out()) { struct getter : T { - static auto get(T& t) -> typename T::container_type& { + static auto get(const T& t) -> const typename T::container_type& { return t.*(&getter::c); // Access c through the derived class. } }; diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 0ce88ba4..e1d384d7 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -424,6 +424,7 @@ TEST(ranges_test, container_adaptor) { s.push(1); s.push(2); EXPECT_EQ(fmt::format("{}", s), "[1, 2]"); + EXPECT_EQ(fmt::format("{}", const_cast(s)), "[1, 2]"); } {