Added format_as for std::vector<bool>::reference

This commit is contained in:
Felix 2023-08-02 21:43:52 -04:00
parent 8a4bec5cf5
commit 8cb0961fba
2 changed files with 14 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <vector>
#include "format.h"
#include "ostream.h"
@ -391,4 +392,12 @@ struct formatter<
};
FMT_END_NAMESPACE
namespace std
{
template <typename T, FMT_ENABLE_IF(std::is_same<T, std::vector<bool>::reference>::value)>
inline auto format_as(T b) -> bool {
return static_cast<bool>(b);
}
}
#endif // FMT_STD_H_

View File

@ -221,3 +221,8 @@ TEST(std_test, exception) {
}
#endif
}
TEST(std_test, format_vector_bool_specialization) {
std::vector<bool> v = {true, false};
EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
}