Skip to content

Commit

Permalink
Added format_as for std::vector<bool>::reference
Browse files Browse the repository at this point in the history
  • Loading branch information
felix642 committed Aug 3, 2023
1 parent 8a4bec5 commit 92e9a7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <memory> // std::uninitialized_copy
#include <stdexcept> // std::runtime_error
#include <system_error> // std::system_error
#include <vector> // std::vector<bool>::reference

#ifdef __cpp_lib_bit_cast
# include <bit> // std::bitcast
Expand Down Expand Up @@ -4076,6 +4077,7 @@ FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
FMT_FORMAT_AS(std::nullptr_t, const void*);
FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>);
FMT_FORMAT_AS(void*, const void*);
FMT_FORMAT_AS(std::vector<bool>::reference, bool);

template <typename Char, size_t N>
struct formatter<Char[N], Char> : formatter<basic_string_view<Char>, Char> {};
Expand Down
5 changes: 5 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2257,3 +2257,8 @@ FMT_END_NAMESPACE
TEST(format_test, formatter_nonconst_char) {
EXPECT_EQ(fmt::format("{}", convertible_to_nonconst_cstring()), "bar");
}

TEST(format_test, format_vector_bool_specialization) {
std::vector<bool> v = {true, false};
EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
}

0 comments on commit 92e9a7f

Please sign in to comment.