Skip to content

Commit

Permalink
AK: Move String::number entirely to header file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ADKaster authored and awesomekling committed Dec 30, 2020
1 parent b4eb734 commit 0c51778
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
15 changes: 0 additions & 15 deletions AK/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions AK/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ class String {
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;

Expand Down

0 comments on commit 0c51778

Please sign in to comment.