From 0c51778510ac2ca98143944c320e04f729e3f8d1 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 29 Dec 2020 22:46:52 -0700 Subject: [PATCH] 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. --- AK/String.cpp | 15 --------------- AK/String.h | 4 ++-- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/AK/String.cpp b/AK/String.cpp index 3c31537f551..360f6479472 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -239,21 +239,6 @@ template Optional String::to_uint() const; template Optional String::to_uint() const; template Optional String::to_uint() const; -template -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; diff --git a/AK/String.h b/AK/String.h index 00544a008c1..a522db11084 100644 --- a/AK/String.h +++ b/AK/String.h @@ -252,8 +252,8 @@ public: return vformatted(fmtstr, VariadicFormatParams { parameters... }); } - template - static String number(T); + template::value>::Type* = nullptr> + static String number(T value) { return formatted("{}", value); } StringView view() const;