AK: Move String::number entirely to header file

Use SFINAE to enforce the fact that it's supposed to only be called for
Arithmetic types, rather than counting on the linker to tell us that an
instantiation of String::number(my_arg) was not found. This also adds
String::number for floating point types as a side-effect.
This commit is contained in:
Andrew Kaster 2020-12-29 22:46:52 -07:00 committed by Andreas Kling
parent b4eb734204
commit 0c51778510
Notes: sideshowbarker 2024-07-19 00:24:14 +09:00
2 changed files with 2 additions and 17 deletions

View file

@ -239,21 +239,6 @@ template Optional<u16> String::to_uint() const;
template Optional<u32> String::to_uint() const;
template Optional<u64> String::to_uint() const;
template<typename T>
String String::number(T value) { return formatted("{}", value); }
template String String::number(unsigned char);
template String String::number(unsigned short);
template String String::number(unsigned int);
template String String::number(unsigned long);
template String String::number(unsigned long long);
template String String::number(char);
template String String::number(short);
template String String::number(int);
template String String::number(long);
template String String::number(long long);
template String String::number(signed char);
String String::format(const char* fmt, ...)
{
StringBuilder builder;

View file

@ -252,8 +252,8 @@ public:
return vformatted(fmtstr, VariadicFormatParams { parameters... });
}
template<typename T>
static String number(T);
template<typename T, typename EnableIf<IsArithmetic<T>::value>::Type* = nullptr>
static String number(T value) { return formatted("{}", value); }
StringView view() const;