From 8cb0961fba2ca742510f120f6d85909050e615ec Mon Sep 17 00:00:00 2001 From: Felix Date: Wed, 2 Aug 2023 21:43:52 -0400 Subject: [PATCH] Added format_as for std::vector::reference --- include/fmt/std.h | 9 +++++++++ test/std-test.cc | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/include/fmt/std.h b/include/fmt/std.h index a71a59db..62e091ce 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "format.h" #include "ostream.h" @@ -391,4 +392,12 @@ struct formatter< }; FMT_END_NAMESPACE +namespace std +{ +template ::reference>::value)> +inline auto format_as(T b) -> bool { + return static_cast(b); +} +} + #endif // FMT_STD_H_ diff --git a/test/std-test.cc b/test/std-test.cc index fda8e96b..643d93c6 100644 --- a/test/std-test.cc +++ b/test/std-test.cc @@ -221,3 +221,8 @@ TEST(std_test, exception) { } #endif } + +TEST(std_test, format_vector_bool_specialization) { + std::vector v = {true, false}; + EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false"); +}