From 8ac0dab15d6b1c97ea2af45c1a4d66ce335d7740 Mon Sep 17 00:00:00 2001 From: Tobias Zindl Date: Thu, 5 Oct 2023 22:52:18 +0200 Subject: [PATCH] :sparkles: add is_same trait --- include/zll/meta/is_same.hpp | 18 ++++++++++++++++++ include/zll/type_traits.hpp | 6 ++++++ tests/unit_tests/meson.build | 1 + tests/unit_tests/meta/is_same_tests.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 include/zll/meta/is_same.hpp create mode 100644 include/zll/type_traits.hpp create mode 100644 tests/unit_tests/meta/is_same_tests.cpp diff --git a/include/zll/meta/is_same.hpp b/include/zll/meta/is_same.hpp new file mode 100644 index 0000000..bae98a6 --- /dev/null +++ b/include/zll/meta/is_same.hpp @@ -0,0 +1,18 @@ +#ifndef ZLL_META_ISSAME_HPP +#define ZLL_META_ISSAME_HPP + +#include "zll/meta/integral_constant.hpp" + +namespace zll { +namespace meta { + +template +struct is_same : false_type {}; + +template +struct is_same : true_type {}; + +} // namespace meta +} // namespace zll + +#endif // ZLL_META_ISSAME_HPP diff --git a/include/zll/type_traits.hpp b/include/zll/type_traits.hpp new file mode 100644 index 0000000..15b8794 --- /dev/null +++ b/include/zll/type_traits.hpp @@ -0,0 +1,6 @@ +#ifndef ZLL_TYPETRAITS_HPP +#define ZLL_TYPETRAITS_HPP + +#include "zll/meta/is_same.hpp" + +#endif // ZLL_TYPETRAITS_HPP diff --git a/tests/unit_tests/meson.build b/tests/unit_tests/meson.build index cf821f8..228f27d 100644 --- a/tests/unit_tests/meson.build +++ b/tests/unit_tests/meson.build @@ -1,6 +1,7 @@ unit_tests_srcs = [ 'meta/integral_constant_tests.cpp', + 'meta/is_same_tests.cpp', 'main.cpp', ] diff --git a/tests/unit_tests/meta/is_same_tests.cpp b/tests/unit_tests/meta/is_same_tests.cpp new file mode 100644 index 0000000..574c9d5 --- /dev/null +++ b/tests/unit_tests/meta/is_same_tests.cpp @@ -0,0 +1,24 @@ +#include "zll/meta/is_same.hpp" + +#include + +struct test_dummy {}; +struct test_child : test_dummy {}; + +UTEST(meta_is_same, compare_same) { + ASSERT_TRUE((zll::meta::is_same::value)); + ASSERT_TRUE((zll::meta::is_same::value)); + ASSERT_TRUE((zll::meta::is_same::value)); + ASSERT_TRUE((zll::meta::is_same::value)); + ASSERT_TRUE((zll::meta::is_same::value)); + ASSERT_TRUE((zll::meta::is_same::value)); +} + +UTEST(meta_is_same, compare_not_same) { + ASSERT_FALSE((zll::meta::is_same::value)); + ASSERT_FALSE((zll::meta::is_same::value)); + ASSERT_FALSE((zll::meta::is_same::value)); + ASSERT_FALSE((zll::meta::is_same::value)); + ASSERT_FALSE((zll::meta::is_same::value)); + ASSERT_FALSE((zll::meta::is_same::value)); +}