1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 07:35:07 +00:00

LibCore+LibGUI: Add is<T>(CObject&) and to<T>(CObject&) helpers.

This commit is contained in:
Andreas Kling 2019-05-27 04:06:01 +02:00
parent 723ba91f74
commit 0c85d3dba9
5 changed files with 53 additions and 30 deletions

View file

@ -58,3 +58,20 @@ private:
bool m_widget { false };
Vector<CObject*> m_children;
};
template<typename T> inline bool is(const CObject&) { return false; }
template<> inline bool is<CObject>(const CObject&) { return true; }
template<typename T>
inline T& to(CObject& object)
{
ASSERT(is<T>(object));
return static_cast<T&>(object);
}
template<typename T>
inline const T& to(const CObject& object)
{
ASSERT(is<T>(object));
return static_cast<const T&>(object);
}