LibCore: CObjects without is<T> specialization shouldn't LARP as others.

This commit is contained in:
Andreas Kling 2019-06-01 14:11:31 +02:00
parent a4726b846c
commit b8e705da0e
2 changed files with 8 additions and 3 deletions

View file

@ -293,3 +293,4 @@ using AK::max;
using AK::min;
using AK::move;
using AK::swap;
using AK::RemoveConst;

View file

@ -1,6 +1,7 @@
#pragma once
#include <AK/Function.h>
#include <AK/StdLibExtras.h>
#include <AK/Vector.h>
#include <AK/Weakable.h>
@ -63,19 +64,22 @@ private:
};
template<typename T>
inline bool is(const CObject&) { return true; }
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));
ASSERT(is<typename RemoveConst<T>::Type>(object));
return static_cast<T&>(object);
}
template<typename T>
inline const T& to(const CObject& object)
{
ASSERT(is<T>(object));
ASSERT(is<typename RemoveConst<T>::Type>(object));
return static_cast<const T&>(object);
}