Fix the default locale in ostream_formatter
This commit is contained in:
@@ -17,7 +17,7 @@ struct test {};
|
||||
// included after fmt/format.h.
|
||||
namespace fmt {
|
||||
template <> struct formatter<test> : formatter<int> {
|
||||
auto format(const test&, format_context& ctx) -> decltype(ctx.out()) {
|
||||
auto format(const test&, format_context& ctx) const -> decltype(ctx.out()) {
|
||||
return formatter<int>::format(42, ctx);
|
||||
}
|
||||
};
|
||||
@@ -289,3 +289,20 @@ TEST(ostream_test, closed_ofstream) {
|
||||
std::ofstream ofs;
|
||||
fmt::print(ofs, "discard");
|
||||
}
|
||||
|
||||
struct unlocalized {};
|
||||
|
||||
auto operator<<(std::ostream& os, unlocalized)
|
||||
-> std::ostream& {
|
||||
return os << 12345;
|
||||
}
|
||||
|
||||
namespace fmt {
|
||||
template <> struct formatter<unlocalized> : ostream_formatter {};
|
||||
} // namespace fmt
|
||||
|
||||
TEST(ostream_test, unlocalized) {
|
||||
auto loc = get_locale("en_US.UTF-8");
|
||||
std::locale::global(loc);
|
||||
EXPECT_EQ(fmt::format(loc, "{}", unlocalized()), "12345");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user