mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
Add xchar support for fmt::streamed().
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
parent
c4ee726532
commit
b31d1a75a0
@ -142,12 +142,13 @@ struct basic_ostream_formatter : formatter<basic_string_view<Char>, Char> {
|
|||||||
|
|
||||||
using ostream_formatter = basic_ostream_formatter<char>;
|
using ostream_formatter = basic_ostream_formatter<char>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Char>
|
||||||
struct formatter<detail::streamed_view<T>> : ostream_formatter {
|
struct formatter<detail::streamed_view<T>, Char>
|
||||||
|
: basic_ostream_formatter<Char> {
|
||||||
template <typename OutputIt>
|
template <typename OutputIt>
|
||||||
auto format(detail::streamed_view<T> view,
|
auto format(detail::streamed_view<T> view,
|
||||||
basic_format_context<OutputIt, char>& ctx) const -> OutputIt {
|
basic_format_context<OutputIt, Char>& ctx) const -> OutputIt {
|
||||||
return ostream_formatter::format(view.value, ctx);
|
return basic_ostream_formatter<Char>::format(view.value, ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -229,6 +229,19 @@ TEST(xchar_test, enum) {
|
|||||||
EXPECT_EQ(L"0", fmt::format(L"{}", unstreamable_enum()));
|
EXPECT_EQ(L"0", fmt::format(L"{}", unstreamable_enum()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct streamable_and_unformattable {};
|
||||||
|
|
||||||
|
auto operator<<(std::wostream& os, streamable_and_unformattable)
|
||||||
|
-> std::wostream& {
|
||||||
|
return os << L"foo";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(xchar_test, streamed) {
|
||||||
|
EXPECT_FALSE(fmt::is_formattable<streamable_and_unformattable>());
|
||||||
|
EXPECT_EQ(fmt::format(L"{}", fmt::streamed(streamable_and_unformattable())),
|
||||||
|
L"foo");
|
||||||
|
}
|
||||||
|
|
||||||
TEST(xchar_test, sign_not_truncated) {
|
TEST(xchar_test, sign_not_truncated) {
|
||||||
wchar_t format_str[] = {
|
wchar_t format_str[] = {
|
||||||
L'{', L':',
|
L'{', L':',
|
||||||
|
Loading…
Reference in New Issue
Block a user