mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
AK: Allow as to perform dynamic cast where necessary
This aligns the behavior of `as` with `is` and `as_if`.
This commit is contained in:
parent
1f87a09503
commit
fb56da4144
|
|
@ -35,22 +35,6 @@ ALWAYS_INLINE bool is(NonnullRefPtr<InputType> const& input)
|
|||
return is<OutputType>(*input);
|
||||
}
|
||||
|
||||
template<typename OutputType, typename InputType>
|
||||
ALWAYS_INLINE CopyConst<InputType, OutputType>* as(InputType* input)
|
||||
{
|
||||
static_assert(IsBaseOf<InputType, OutputType>);
|
||||
VERIFY(!input || is<OutputType>(*input));
|
||||
return static_cast<CopyConst<InputType, OutputType>*>(input);
|
||||
}
|
||||
|
||||
template<typename OutputType, typename InputType>
|
||||
ALWAYS_INLINE CopyConst<InputType, OutputType>& as(InputType& input)
|
||||
{
|
||||
static_assert(IsBaseOf<InputType, OutputType>);
|
||||
VERIFY(is<OutputType>(input));
|
||||
return static_cast<CopyConst<InputType, OutputType>&>(input);
|
||||
}
|
||||
|
||||
template<typename OutputType, typename InputType>
|
||||
ALWAYS_INLINE CopyConst<InputType, OutputType>* as_if(InputType& input)
|
||||
{
|
||||
|
|
@ -71,6 +55,24 @@ ALWAYS_INLINE CopyConst<InputType, OutputType>* as_if(InputType* input)
|
|||
return as_if<OutputType>(*input);
|
||||
}
|
||||
|
||||
template<typename OutputType, typename InputType>
|
||||
ALWAYS_INLINE CopyConst<InputType, OutputType>& as(InputType& input)
|
||||
{
|
||||
auto* result = as_if<OutputType>(input);
|
||||
VERIFY(result);
|
||||
return *result;
|
||||
}
|
||||
|
||||
template<typename OutputType, typename InputType>
|
||||
ALWAYS_INLINE CopyConst<InputType, OutputType>* as(InputType* input)
|
||||
{
|
||||
if (!input)
|
||||
return nullptr;
|
||||
auto* result = as_if<OutputType>(input);
|
||||
VERIFY(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user