Make locales work with any character type

This commit is contained in:
Victor Zverovich 2018-10-28 07:36:35 -07:00
parent bdda4d6030
commit 324eac1aa5
3 changed files with 16 additions and 10 deletions

View File

@ -214,13 +214,10 @@ class locale {
namespace internal {
template <typename Char>
FMT_FUNC Char thousands_sep(locale_provider *lp) {
FMT_FUNC Char thousands_sep_impl(locale_provider *lp) {
std::locale loc = lp ? lp->locale().get() : std::locale();
return std::use_facet<std::numpunct<Char>>(loc).thousands_sep();
}
template <> FMT_FUNC char8_t thousands_sep<char8_t>(locale_provider *) {
return static_cast<char8_t>(',');
}
}
#else
template <typename Char>

View File

@ -1034,7 +1034,17 @@ class add_thousands_sep {
};
template <typename Char>
FMT_API Char thousands_sep(locale_provider *lp);
FMT_API Char thousands_sep_impl(locale_provider *lp);
template <typename Char>
inline Char thousands_sep(locale_provider *lp) {
return Char(thousands_sep_impl<char>(lp));
}
template <>
inline wchar_t thousands_sep(locale_provider *lp) {
return thousands_sep_impl<wchar_t>(lp);
}
// Formats a decimal unsigned integer value writing into buffer.
// thousands_sep is a functor that is called after writing each char to
@ -3416,7 +3426,7 @@ struct it_category<T, typename void_<typename T::iterator_category>::type> {
typedef typename T::iterator_category type;
};
// Detect if *any* given type models the OutputIterator concept
// Detect if *any* given type models the OutputIterator concept.
template <typename It>
class is_output_iterator {
// Check for mutability because all iterator categories derived from
@ -3434,10 +3444,9 @@ class is_output_iterator {
typedef decltype(test<It>(typename it_category<It>::type{})) type;
typedef typename std::remove_reference<type>::type result;
public:
public:
static const bool value = !std::is_const<result>::value;
};
} // internal
template <typename OutputIt, typename Char = char>

View File

@ -12,7 +12,7 @@ template struct internal::basic_data<void>;
// Explicit instantiations for char.
template FMT_API char internal::thousands_sep(locale_provider *lp);
template FMT_API char internal::thousands_sep_impl(locale_provider *lp);
template void internal::basic_buffer<char>::append(const char *, const char *);
@ -38,7 +38,7 @@ template FMT_API void internal::sprintf_format(
// Explicit instantiations for wchar_t.
template FMT_API wchar_t internal::thousands_sep(locale_provider *);
template FMT_API wchar_t internal::thousands_sep_impl(locale_provider *);
template void internal::basic_buffer<wchar_t>::append(
const wchar_t *, const wchar_t *);