AK: Assert that is<T>() input and output types are not the same

This makes it a compile error to use is<T>() where the input and output
types are known to be the same at compile time.

(cherry picked from commit 82a63e350cb9a67cbd3aa659d909ae9e6599e93f)
This commit is contained in:
Tim Ledbetter authored and Nico Weber committed 2024-09-28 14:14:28 -04:00
1 parent eab3d1092d
commit d11ca444d0
1 file changed
+2
+2
View File
@@ -7,6 +7,7 @@
#pragma once
#include <AK/Assertions.h>
#include <AK/Concepts.h>
#include <AK/Forward.h>
#include <AK/Platform.h>
@@ -15,6 +16,7 @@ namespace AK {
template<typename OutputType, typename InputType>
ALWAYS_INLINE bool is(InputType& input)
{
static_assert(!SameAs<OutputType, InputType>);
if constexpr (requires { input.template fast_is<OutputType>(); }) {
return input.template fast_is<OutputType>();
}