Skip to content

Commit cfa8775

Browse files
committed
std::format only supports char and wchar_t
1 parent d450d6b commit cfa8775

File tree

2 files changed

+2
-58
lines changed

2 files changed

+2
-58
lines changed

include/boost/decimal/format.hpp

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,6 @@ struct formattable_character_type<char> : std::true_type {};
171171
template <>
172172
struct formattable_character_type<wchar_t> : std::true_type {};
173173

174-
template <>
175-
struct formattable_character_type<char8_t> : std::true_type {};
176-
177-
template <>
178-
struct formattable_character_type<char16_t> : std::true_type {};
179-
180-
template <>
181-
struct formattable_character_type<char32_t> : std::true_type {};
182-
183174
template <typename CharT>
184175
inline constexpr bool is_formattable_character_type_v = formattable_character_type<CharT>::value;
185176

@@ -305,11 +296,12 @@ struct formatter<T>
305296
s.resize(initial_length + offset);
306297
}
307298

299+
// std <format> only supports char and wchar_t
308300
if constexpr (std::is_same_v<CharType, char>)
309301
{
310302
return std::format_to(ctx.out(), "{}", s);
311303
}
312-
else if constexpr (std::is_same_v<CharType, wchar_t>)
304+
else
313305
{
314306
std::wstring result;
315307
result.reserve(s.size());
@@ -320,30 +312,6 @@ struct formatter<T>
320312

321313
return std::format_to(ctx.out(), L"{}", result);
322314
}
323-
else
324-
{
325-
// For other character types (char16_t, char32_t, etc.)
326-
327-
std::basic_string<CharType> result;
328-
result.reserve(s.size());
329-
for (const char c : s)
330-
{
331-
result.push_back(static_cast<CharType>(static_cast<unsigned char>(c)));
332-
}
333-
334-
if constexpr (std::is_same_v<CharType, char16_t>)
335-
{
336-
return std::format_to(ctx.out(), u"{}", result);
337-
}
338-
else if constexpr (std::is_same_v<CharType, char32_t>)
339-
{
340-
return std::format_to(ctx.out(), U"{}", result);
341-
}
342-
else
343-
{
344-
return std::format_to(ctx.out(), u8"{}", result);
345-
}
346-
}
347315
}
348316
};
349317

test/test_format.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -275,30 +275,6 @@ void test_wide_strings()
275275
BOOST_TEST(std::format(L"{}", T{10000}) == L"10000");
276276
BOOST_TEST(std::format(L"{}", T{210000}) == L"210000");
277277
BOOST_TEST(std::format(L"{}", T{2100000}) == L"2100000");
278-
279-
BOOST_TEST(std::format(u"{}", T{1}) == u"1");
280-
BOOST_TEST(std::format(u"{}", T{10}) == u"10");
281-
BOOST_TEST(std::format(u"{}", T{100}) == u"100");
282-
BOOST_TEST(std::format(u"{}", T{1000}) == u"1000");
283-
BOOST_TEST(std::format(u"{}", T{10000}) == u"10000");
284-
BOOST_TEST(std::format(u"{}", T{210000}) == u"210000");
285-
BOOST_TEST(std::format(u"{}", T{2100000}) == u"2100000");
286-
287-
BOOST_TEST(std::format(U"{}", T{1}) == U"1");
288-
BOOST_TEST(std::format(U"{}", T{10}) == U"10");
289-
BOOST_TEST(std::format(U"{}", T{100}) == U"100");
290-
BOOST_TEST(std::format(U"{}", T{1000}) == U"1000");
291-
BOOST_TEST(std::format(U"{}", T{10000}) == U"10000");
292-
BOOST_TEST(std::format(U"{}", T{210000}) == U"210000");
293-
BOOST_TEST(std::format(U"{}", T{2100000}) == U"2100000");
294-
295-
BOOST_TEST(std::format(u8"{}", T{1}) == u8"1");
296-
BOOST_TEST(std::format(u8"{}", T{10}) == u8"10");
297-
BOOST_TEST(std::format(u8"{}", T{100}) == u8"100");
298-
BOOST_TEST(std::format(u8"{}", T{1000}) == u8"1000");
299-
BOOST_TEST(std::format(u8"{}", T{10000}) == u8"10000");
300-
BOOST_TEST(std::format(u8"{}", T{210000}) == u8"210000");
301-
BOOST_TEST(std::format(u8"{}", T{2100000}) == u8"2100000");
302278
}
303279

304280
int main()

0 commit comments

Comments
 (0)