/* * Copyright (c) 2020-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace AK { template ALWAYS_INLINE bool is(InputType& input) { static_assert(!SameAs); if constexpr (requires { input.template fast_is(); }) { return input.template fast_is(); } return dynamic_cast*>(&input); } template ALWAYS_INLINE bool is(InputType* input) { return input && is(*input); } template ALWAYS_INLINE bool is(NonnullRefPtr const& input) { return is(*input); } template ALWAYS_INLINE CopyConst* verify_cast(InputType* input) { static_assert(IsBaseOf); VERIFY(!input || is(*input)); return static_cast*>(input); } template ALWAYS_INLINE CopyConst& verify_cast(InputType& input) { static_assert(IsBaseOf); VERIFY(is(input)); return static_cast&>(input); } } #if USING_AK_GLOBALLY using AK::is; using AK::verify_cast; #endif