summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-01 15:33:30 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-01 15:33:30 +0100
commit865f524d5b1257ec77b2d17b93ec777799b4c4ab (patch)
treed99597100b4f0f8670aa0edd8ebe67d5ae60a35a /AK
parent7c3b6b10e4230a24dbe44df4f942d63ee27cac89 (diff)
downloadserenity-865f524d5b1257ec77b2d17b93ec777799b4c4ab.zip
AK+LibGUI+LibWeb: Remove AK::TypeTraits in favor of RTTI-based helpers
Now that we have RTTI in userspace, we can do away with all this manual hackery and use dynamic_cast. We keep the is<T> and downcast<T> helpers since they still provide good readability improvements. Note that unlike dynamic_cast<T>, downcast<T> does not fail in a recoverable way, but will assert if the object being casted is not a T.
Diffstat (limited to 'AK')
-rw-r--r--AK/TypeCasts.h37
1 files changed, 4 insertions, 33 deletions
diff --git a/AK/TypeCasts.h b/AK/TypeCasts.h
index 434da021e6..c218ba8568 100644
--- a/AK/TypeCasts.h
+++ b/AK/TypeCasts.h
@@ -30,30 +30,16 @@
namespace AK {
-template<typename OutputType, typename InputType, bool is_base_type = IsBaseOf<OutputType, InputType>::value>
-struct TypeTraits {
- static bool has_type(InputType&)
- {
- static_assert(IsVoid<OutputType>::value, "No TypeTraits for this type");
- return false;
- }
-};
-
-template<typename OutputType, typename InputType>
-struct TypeTraits<OutputType, InputType, true> {
- static bool has_type(InputType&) { return true; }
-};
-
template<typename OutputType, typename InputType>
-inline bool is(InputType* input)
+inline bool is(InputType& input)
{
- return input && TypeTraits<const OutputType, const InputType>::has_type(*input);
+ return dynamic_cast<CopyConst<InputType, OutputType>*>(&input);
}
template<typename OutputType, typename InputType>
-inline bool is(InputType& input)
+inline bool is(InputType* input)
{
- return TypeTraits<const OutputType, const InputType>::has_type(input);
+ return input && is<OutputType>(*input);
}
template<typename OutputType, typename InputType>
@@ -72,22 +58,7 @@ inline CopyConst<InputType, OutputType>& downcast(InputType& input)
return static_cast<CopyConst<InputType, OutputType>&>(input);
}
-#define AK_BEGIN_TYPE_TRAITS(ClassName) \
- namespace AK { \
- template<typename InputType> \
- class TypeTraits<const ClassName, InputType, false> { \
- public: \
- static bool has_type(InputType& input) { return is_type(input); } \
- \
- private:
-
-#define AK_END_TYPE_TRAITS() \
- } \
- ; \
- }
-
}
using AK::downcast;
using AK::is;
-using AK::TypeTraits;