forked from fmtlib/fmt
Remove require_wchar and internalize no_formatter_error
This commit is contained in:
@@ -233,6 +233,9 @@ FMT_CONSTEXPR size_t length(const Char *s) {
|
|||||||
#if FMT_GCC_VERSION
|
#if FMT_GCC_VERSION
|
||||||
FMT_CONSTEXPR size_t length(const char *s) { return std::strlen(s); }
|
FMT_CONSTEXPR size_t length(const char *s) { return std::strlen(s); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct no_formatter_error : std::false_type {};
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -340,13 +343,10 @@ class basic_format_arg;
|
|||||||
template <typename Context>
|
template <typename Context>
|
||||||
class basic_format_args;
|
class basic_format_args;
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct no_formatter_error : std::false_type {};
|
|
||||||
|
|
||||||
// A formatter for objects of type T.
|
// A formatter for objects of type T.
|
||||||
template <typename T, typename Char = char, typename Enable = void>
|
template <typename T, typename Char = char, typename Enable = void>
|
||||||
struct formatter {
|
struct formatter {
|
||||||
static_assert(no_formatter_error<T>::value,
|
static_assert(internal::no_formatter_error<T>::value,
|
||||||
"don't know how to format the type, include fmt/ostream.h if it provides "
|
"don't know how to format the type, include fmt/ostream.h if it provides "
|
||||||
"an operator<< that should be used");
|
"an operator<< that should be used");
|
||||||
|
|
||||||
@@ -472,17 +472,6 @@ struct error_handler {
|
|||||||
FMT_API void on_error(const char *message);
|
FMT_API void on_error(const char *message);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Formatting of wide characters and strings into a narrow output is disallowed:
|
|
||||||
// fmt::format("{}", L"test"); // error
|
|
||||||
// To fix this, use a wide format string:
|
|
||||||
// fmt::format(L"{}", L"test");
|
|
||||||
template <typename Char>
|
|
||||||
inline void require_wchar() {
|
|
||||||
static_assert(
|
|
||||||
std::is_same<wchar_t, Char>::value,
|
|
||||||
"formatting of wide characters into a narrow output is disallowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
struct named_arg_base;
|
struct named_arg_base;
|
||||||
|
|
||||||
@@ -639,15 +628,12 @@ FMT_MAKE_VALUE_SAME(long_long_type, long long)
|
|||||||
FMT_MAKE_VALUE_SAME(ulong_long_type, unsigned long long)
|
FMT_MAKE_VALUE_SAME(ulong_long_type, unsigned long long)
|
||||||
FMT_MAKE_VALUE(int_type, signed char, int)
|
FMT_MAKE_VALUE(int_type, signed char, int)
|
||||||
FMT_MAKE_VALUE(uint_type, unsigned char, unsigned)
|
FMT_MAKE_VALUE(uint_type, unsigned char, unsigned)
|
||||||
FMT_MAKE_VALUE(char_type, char, int)
|
FMT_MAKE_VALUE(char_type, typename C::char_type, int)
|
||||||
|
|
||||||
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
inline init<C, int, char_type> make_value(wchar_t val) {
|
FMT_CONSTEXPR typename std::enable_if<
|
||||||
require_wchar<typename C::char_type>();
|
!std::is_same<typename C::char_type, char>::value,
|
||||||
return static_cast<int>(val);
|
init<C, int, char_type>>::type make_value(char val) { return val; }
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FMT_MAKE_VALUE(double_type, float, double)
|
FMT_MAKE_VALUE(double_type, float, double)
|
||||||
FMT_MAKE_VALUE_SAME(double_type, double)
|
FMT_MAKE_VALUE_SAME(double_type, double)
|
||||||
|
@@ -2740,9 +2740,8 @@ class basic_writer {
|
|||||||
void write(char value) {
|
void write(char value) {
|
||||||
*reserve(1) = value;
|
*reserve(1) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(wchar_t value) {
|
void write(wchar_t value) {
|
||||||
internal::require_wchar<char_type>();
|
static_assert(std::is_same<char_type, wchar_t>::value, "");
|
||||||
*reserve(1) = value;
|
*reserve(1) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2755,9 +2754,8 @@ class basic_writer {
|
|||||||
auto &&it = reserve(value.size());
|
auto &&it = reserve(value.size());
|
||||||
it = std::copy(value.begin(), value.end(), it);
|
it = std::copy(value.begin(), value.end(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(wstring_view value) {
|
void write(wstring_view value) {
|
||||||
internal::require_wchar<char_type>();
|
static_assert(std::is_same<char_type, wchar_t>::value, "");
|
||||||
auto &&it = reserve(value.size());
|
auto &&it = reserve(value.size());
|
||||||
it = std::copy(value.begin(), value.end(), it);
|
it = std::copy(value.begin(), value.end(), it);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user