mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
AK: Allow as_if
to perform dynamic cast when necessary
This means that if `is<OutputType>(x)` is true, that `as_if<OutputType>(x)` should always succeed.
This commit is contained in:
parent
6ebe19d13b
commit
1f87a09503
Notes:
github-actions[bot]
2025-01-31 13:30:59 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/1f87a09503c Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3414 Reviewed-by: https://github.com/gmta ✅
1 changed files with 5 additions and 1 deletions
|
@ -56,7 +56,11 @@ ALWAYS_INLINE CopyConst<InputType, OutputType>* as_if(InputType& input)
|
|||
{
|
||||
if (!is<OutputType>(input))
|
||||
return nullptr;
|
||||
return static_cast<CopyConst<InputType, OutputType>*>(&input);
|
||||
if constexpr (IsBaseOf<InputType, OutputType>) {
|
||||
return static_cast<CopyConst<InputType, OutputType>*>(&input);
|
||||
} else {
|
||||
return dynamic_cast<CopyConst<InputType, OutputType>*>(&input);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename OutputType, typename InputType>
|
||||
|
|
Loading…
Add table
Reference in a new issue