mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-27 06:35:37 +00:00
Remove char_traits (#1117)
This commit is contained in:
parent
397e8dd9d5
commit
dc94010fa5
@ -254,21 +254,12 @@ template <> FMT_FUNC int count_digits<4>(internal::uintptr_t n) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int char_traits<char>::format_float(char* buf, std::size_t size,
|
||||
const char* format, int precision,
|
||||
T value) {
|
||||
int format_float(char* buf, std::size_t size, const char* format, int precision,
|
||||
T value) {
|
||||
return precision < 0 ? FMT_SNPRINTF(buf, size, format, value)
|
||||
: FMT_SNPRINTF(buf, size, format, precision, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int char_traits<wchar_t>::format_float(wchar_t* buf, std::size_t size,
|
||||
const wchar_t* format, int precision,
|
||||
T value) {
|
||||
return precision < 0 ? FMT_SWPRINTF(buf, size, format, value)
|
||||
: FMT_SWPRINTF(buf, size, format, precision, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const char basic_data<T>::DIGITS[] =
|
||||
"0001020304050607080910111213141516171819"
|
||||
@ -758,8 +749,8 @@ void sprintf_format(Double value, internal::buffer<char>& buf,
|
||||
for (;;) {
|
||||
std::size_t buffer_size = buf.capacity();
|
||||
start = &buf[0];
|
||||
int result = internal::char_traits<char>::format_float(
|
||||
start, buffer_size, format, spec.precision, value);
|
||||
int result =
|
||||
format_float(start, buffer_size, format, spec.precision, value);
|
||||
if (result >= 0) {
|
||||
unsigned n = internal::to_unsigned(result);
|
||||
if (n < buf.capacity()) {
|
||||
|
@ -552,40 +552,6 @@ typedef basic_memory_buffer<wchar_t> wmemory_buffer;
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename Char> struct char_traits;
|
||||
|
||||
template <> struct char_traits<char> {
|
||||
// Formats a floating-point number.
|
||||
template <typename T>
|
||||
FMT_API static int format_float(char* buffer, std::size_t size,
|
||||
const char* format, int precision, T value);
|
||||
};
|
||||
|
||||
template <> struct char_traits<wchar_t> {
|
||||
template <typename T>
|
||||
FMT_API static int format_float(wchar_t* buffer, std::size_t size,
|
||||
const wchar_t* format, int precision,
|
||||
T value);
|
||||
};
|
||||
|
||||
#if FMT_USE_EXTERN_TEMPLATES
|
||||
extern template int char_traits<char>::format_float<double>(char* buffer,
|
||||
std::size_t size,
|
||||
const char* format,
|
||||
int precision,
|
||||
double value);
|
||||
extern template int char_traits<char>::format_float<long double>(
|
||||
char* buffer, std::size_t size, const char* format, int precision,
|
||||
long double value);
|
||||
|
||||
extern template int char_traits<wchar_t>::format_float<double>(
|
||||
wchar_t* buffer, std::size_t size, const wchar_t* format, int precision,
|
||||
double value);
|
||||
extern template int char_traits<wchar_t>::format_float<long double>(
|
||||
wchar_t* buffer, std::size_t size, const wchar_t* format, int precision,
|
||||
long double value);
|
||||
#endif
|
||||
|
||||
// A workaround for std::string not having mutable data() until C++17.
|
||||
template <typename Char> inline Char* get_data(std::basic_string<Char>& s) {
|
||||
return &s[0];
|
||||
|
@ -28,16 +28,6 @@ template FMT_API void internal::buffer<char>::append(const char*, const char*);
|
||||
template FMT_API void internal::arg_map<format_context>::init(
|
||||
const basic_format_args<format_context>& args);
|
||||
|
||||
template FMT_API int internal::char_traits<char>::format_float(char*,
|
||||
std::size_t,
|
||||
const char*, int,
|
||||
double);
|
||||
|
||||
template FMT_API int internal::char_traits<char>::format_float(char*,
|
||||
std::size_t,
|
||||
const char*, int,
|
||||
long double);
|
||||
|
||||
template FMT_API std::string internal::vformat<char>(
|
||||
string_view, basic_format_args<format_context>);
|
||||
|
||||
@ -60,12 +50,6 @@ template FMT_API void internal::buffer<wchar_t>::append(const wchar_t*,
|
||||
template FMT_API void internal::arg_map<wformat_context>::init(
|
||||
const basic_format_args<wformat_context>&);
|
||||
|
||||
template FMT_API int internal::char_traits<wchar_t>::format_float(
|
||||
wchar_t*, std::size_t, const wchar_t*, int, double);
|
||||
|
||||
template FMT_API int internal::char_traits<wchar_t>::format_float(
|
||||
wchar_t*, std::size_t, const wchar_t*, int, long double);
|
||||
|
||||
template FMT_API std::wstring internal::vformat<wchar_t>(
|
||||
wstring_view, basic_format_args<wformat_context>);
|
||||
FMT_END_NAMESPACE
|
||||
|
@ -2538,3 +2538,8 @@ TEST(FormatTest, EmphasisNonHeaderOnly) {
|
||||
EXPECT_EQ(fmt::format(fmt::emphasis::bold, "bold error"),
|
||||
"\x1b[1mbold error\x1b[0m");
|
||||
}
|
||||
|
||||
TEST(FormatTest, CharTraitsIsNotAmbiguous) {
|
||||
using namespace std;
|
||||
char_traits<char>::char_type c;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user