Skip to content

Commit 040412c

Browse files
committed
Improve message for unsupported character types
1 parent f3b2fe2 commit 040412c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

include/boost/decimal/format.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ constexpr auto parse_impl(ParseContext &ctx)
162162
return std::make_tuple(ctx_precision, fmt, is_upper, padding_digits, sign_character, use_locale, it);
163163
}
164164

165+
template <typename>
166+
struct formattable_character_type : std::false_type {};
167+
168+
template <>
169+
struct formattable_character_type<char> : std::true_type {};
170+
171+
template <>
172+
struct formattable_character_type<wchar_t> : std::true_type {};
173+
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+
183+
template <typename CharT>
184+
inline constexpr bool is_formattable_character_type_v = formattable_character_type<CharT>::value;
185+
165186
} // Namespace boost::decimal::detail
166187

167188
namespace std {
@@ -187,6 +208,8 @@ struct formatter<T>
187208
template <typename CharType>
188209
constexpr auto parse(basic_format_parse_context<CharType>& ctx)
189210
{
211+
static_assert(boost::decimal::detail::is_formattable_character_type_v<CharType>, "This is an unsupported character type. Only the following can be used: char, char8_t, char16_t, char32_t, or wchar_t");
212+
190213
const auto res {boost::decimal::detail::parse_impl(ctx)};
191214

192215
ctx_precision = std::get<0>(res);

0 commit comments

Comments
 (0)