From 473443c8580f941448fbc6f20a4389b4912d9f4e Mon Sep 17 00:00:00 2001 From: Tobias Zindl Date: Fri, 6 Oct 2023 07:12:43 +0200 Subject: [PATCH 1/2] :sparkles: add remove_cv traits --- include/zll/meta/remove_cv.hpp | 27 +++++++++++++++++ include/zll/type_traits.hpp | 3 ++ tests/unit_tests/meson.build | 1 + tests/unit_tests/meta/remove_cv_tests.cpp | 36 +++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 include/zll/meta/remove_cv.hpp create mode 100644 tests/unit_tests/meta/remove_cv_tests.cpp diff --git a/include/zll/meta/remove_cv.hpp b/include/zll/meta/remove_cv.hpp new file mode 100644 index 0000000..22958e3 --- /dev/null +++ b/include/zll/meta/remove_cv.hpp @@ -0,0 +1,27 @@ +#ifndef ZLL_META_REMOVECV_HPP +#define ZLL_META_REMOVECV_HPP + +namespace zll { +namespace meta { + +// clang-format off +template struct remove_const { typedef T type; }; +template struct remove_const { typedef T type; }; +// clang-format on + +// clang-format off +template struct remove_volatile { typedef T type; }; +template struct remove_volatile { typedef T type; }; +// clang-format on + +// clang-format off +template struct remove_cv { typedef T type; }; +template struct remove_cv { typedef T type; }; +template struct remove_cv { typedef T type; }; +template struct remove_cv { typedef T type; }; +// clang-format on + +} // namespace meta +} // namespace zll + +#endif // ZLL_META_ISSAME_HPP diff --git a/include/zll/type_traits.hpp b/include/zll/type_traits.hpp index 15b8794..b58ea95 100644 --- a/include/zll/type_traits.hpp +++ b/include/zll/type_traits.hpp @@ -3,4 +3,7 @@ #include "zll/meta/is_same.hpp" +#include "zll/meta/remove_cv.hpp" + + #endif // ZLL_TYPETRAITS_HPP diff --git a/tests/unit_tests/meson.build b/tests/unit_tests/meson.build index 228f27d..6b4a9ed 100644 --- a/tests/unit_tests/meson.build +++ b/tests/unit_tests/meson.build @@ -2,6 +2,7 @@ unit_tests_srcs = [ 'meta/integral_constant_tests.cpp', 'meta/is_same_tests.cpp', + 'meta/remove_cv_tests.cpp', 'main.cpp', ] diff --git a/tests/unit_tests/meta/remove_cv_tests.cpp b/tests/unit_tests/meta/remove_cv_tests.cpp new file mode 100644 index 0000000..ebc666d --- /dev/null +++ b/tests/unit_tests/meta/remove_cv_tests.cpp @@ -0,0 +1,36 @@ +#include "zll/meta/remove_cv.hpp" +#include "zll/meta/is_same.hpp" + +#include + +struct test_dummy {}; +struct test_child : test_dummy {}; + +UTEST(meta_remove_cv, remove_const) { + ASSERT_TRUE((zll::meta::is_same::type, int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, volatile int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, volatile int>::value)); +} + +UTEST(meta_remove_cv, remove_volatile) { + ASSERT_TRUE((zll::meta::is_same::type, int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, const int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, const int>::value)); +} + +UTEST(meta_remove_cv, remove_cv) { + ASSERT_TRUE((zll::meta::is_same::type, int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, int>::value)); + ASSERT_TRUE((zll::meta::is_same::type, int>::value)); +} +UTEST(meta_remove_cv, remove_cv_pointer) { + ASSERT_TRUE((zll::meta::is_same::type, int*>::value)); + + // remove_cv does not work on pointers + ASSERT_FALSE((zll::meta::is_same::type, int*>::value)); + ASSERT_FALSE((zll::meta::is_same::type, int*>::value)); + ASSERT_FALSE((zll::meta::is_same::type, int*>::value)); +} From 7b1e53ec4e9bef4d9103aabf213eb7c721aac3e0 Mon Sep 17 00:00:00 2001 From: Tobias Zindl Date: Fri, 6 Oct 2023 07:52:20 +0200 Subject: [PATCH 2/2] :sparkles: add is_pointer trait --- include/zll/meta/is_pointer.hpp | 20 ++++++++++++++++++++ include/zll/type_traits.hpp | 1 + tests/unit_tests/meson.build | 3 ++- tests/unit_tests/meta/is_pointer_tests.cpp | 20 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 include/zll/meta/is_pointer.hpp create mode 100644 tests/unit_tests/meta/is_pointer_tests.cpp diff --git a/include/zll/meta/is_pointer.hpp b/include/zll/meta/is_pointer.hpp new file mode 100644 index 0000000..a10152b --- /dev/null +++ b/include/zll/meta/is_pointer.hpp @@ -0,0 +1,20 @@ +#ifndef ZLL_META_ISPOINTER_HPP +#define ZLL_META_ISPOINTER_HPP + +#include "zll/meta/integral_constant.hpp" + +namespace zll { +namespace meta { + +// clang-format off +template struct is_pointer : false_type {}; +template struct is_pointer : true_type {}; +template struct is_pointer : true_type {}; +template struct is_pointer : true_type {}; +template struct is_pointer : true_type {}; +// clang-format on + +} // namespace meta +} // namespace zll + +#endif // ZLL_META_ISPOINTER_HPP diff --git a/include/zll/type_traits.hpp b/include/zll/type_traits.hpp index b58ea95..a206b73 100644 --- a/include/zll/type_traits.hpp +++ b/include/zll/type_traits.hpp @@ -1,6 +1,7 @@ #ifndef ZLL_TYPETRAITS_HPP #define ZLL_TYPETRAITS_HPP +#include "zll/meta/is_pointer.hpp" #include "zll/meta/is_same.hpp" #include "zll/meta/remove_cv.hpp" diff --git a/tests/unit_tests/meson.build b/tests/unit_tests/meson.build index 6b4a9ed..fcfe88b 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_pointer_tests.cpp', 'meta/is_same_tests.cpp', 'meta/remove_cv_tests.cpp', 'main.cpp', @@ -14,4 +15,4 @@ unit_tests_exec = executable( dependencies: [utest_dep, dis_dep], ) -test('zll-unit-tests', unit_tests_exec, suite: 'dis') +test('zll-unit-tests', unit_tests_exec, suite: 'zll') diff --git a/tests/unit_tests/meta/is_pointer_tests.cpp b/tests/unit_tests/meta/is_pointer_tests.cpp new file mode 100644 index 0000000..732f61a --- /dev/null +++ b/tests/unit_tests/meta/is_pointer_tests.cpp @@ -0,0 +1,20 @@ +#include "zll/meta/is_pointer.hpp" +#include "zll/meta/is_same.hpp" + +#include + +struct test_dummy {}; + +UTEST(meta_is_pointer, is_pointer) { + ASSERT_TRUE(zll::meta::is_pointer::value); + ASSERT_TRUE(zll::meta::is_pointer::value); + ASSERT_TRUE(zll::meta::is_pointer::value); + ASSERT_TRUE(zll::meta::is_pointer::value); + ASSERT_TRUE(zll::meta::is_pointer::value); + ASSERT_TRUE(zll::meta::is_pointer::value); + + ASSERT_FALSE(zll::meta::is_pointer::value); + ASSERT_FALSE(zll::meta::is_pointer::value); + ASSERT_FALSE(zll::meta::is_pointer::value); + ASSERT_FALSE(zll::meta::is_pointer::value); +}