From 85209522358c83dc28df2499b4d70c754121e74d Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 29 Apr 2024 13:31:38 +0200 Subject: [PATCH] Meta: Add type compare is() function --- src/ruc/meta/types.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/ruc/meta/types.h diff --git a/src/ruc/meta/types.h b/src/ruc/meta/types.h new file mode 100644 index 0000000..d342710 --- /dev/null +++ b/src/ruc/meta/types.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2023 Riyyi + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +template +inline bool is(U& input) +{ + if constexpr (requires { input.template fastIs(); }) { + return input.template fastIs(); + } + + return typeid(input) == typeid(T); +} + +template +inline bool is(U* input) +{ + return input && is(*input); +}