diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-04-10 18:29:06 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-10 21:01:31 +0200 |
commit | a6e448208052c2d03fca53a4061a367b33167d37 (patch) | |
tree | 0d6f84d1257e2af57d28a3102d0622fcf716782b /AK/Format.h | |
parent | d8d16dea957f15f07ebb08d1578e21d97fc163bc (diff) | |
download | serenity-a6e448208052c2d03fca53a4061a367b33167d37.zip |
AK+Everywhere: Make StdLibExtras templates less wrapper-y
This commit makes the user-facing StdLibExtras templates and utilities
arguably more nice-looking by removing the need to reach into the
wrapper structs generated by them to get the value/type needed.
The C++ standard library had to invent `_v` and `_t` variants (likely
because of backwards compat), but we don't need to cater to any codebase
except our own, so might as well have good things for free. :^)
Diffstat (limited to 'AK/Format.h')
-rw-r--r-- | AK/Format.h | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/AK/Format.h b/AK/Format.h index 8da01d3b26..a46b06c4b5 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -93,10 +93,10 @@ struct TypeErasedParameter { template<typename T> static Type get_type() { - if (IsIntegral<T>::value) - return get_type_from_size(sizeof(T), IsUnsigned<T>::value); - - return Type::Custom; + if constexpr (IsIntegral<T>) + return get_type_from_size(sizeof(T), IsUnsigned<T>); + else + return Type::Custom; } size_t to_size() const; @@ -269,7 +269,7 @@ struct StandardFormatter { }; template<typename T> -struct Formatter<T, typename EnableIf<IsIntegral<T>::value>::Type> : StandardFormatter { +struct Formatter<T, typename EnableIf<IsIntegral<T>>::Type> : StandardFormatter { Formatter() = default; explicit Formatter(StandardFormatter formatter) : StandardFormatter(formatter) @@ -416,11 +416,10 @@ void dmesgln(CheckedFormatString<Parameters...>&& fmt, const Parameters&... para #endif template<typename T, typename = void> -struct HasFormatter : TrueType { -}; +inline constexpr bool HasFormatter = true; + template<typename T> -struct HasFormatter<T, typename Formatter<T>::__no_formatter_defined> : FalseType { -}; +inline constexpr bool HasFormatter<T, typename Formatter<T>::__no_formatter_defined> = false; template<typename T> class FormatIfSupported { @@ -450,7 +449,7 @@ struct __FormatIfSupported<T, true> : Formatter<T> { } }; template<typename T> -struct Formatter<FormatIfSupported<T>> : __FormatIfSupported<T, HasFormatter<T>::value> { +struct Formatter<FormatIfSupported<T>> : __FormatIfSupported<T, HasFormatter<T>> { }; // This is a helper class, the idea is that if you want to implement a formatter you can inherit |