Skip to content

Commit

Permalink
✨ add is_pointer trait
Browse files Browse the repository at this point in the history
  • Loading branch information
zie87 committed Oct 6, 2023
1 parent 9bcaef4 commit 1e6426e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
20 changes: 20 additions & 0 deletions include/zll/meta/is_pointer.hpp
Original file line number Diff line number Diff line change
@@ -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<typename T> struct is_pointer : false_type {};
template<typename T> struct is_pointer<T*> : true_type {};
template<typename T> struct is_pointer<T* const> : true_type {};
template<typename T> struct is_pointer<T* volatile> : true_type {};
template<typename T> struct is_pointer<T* const volatile> : true_type {};
// clang-format on

} // namespace meta
} // namespace zll

#endif // ZLL_META_ISPOINTER_HPP
1 change: 1 addition & 0 deletions include/zll/type_traits.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/meson.build
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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')
20 changes: 20 additions & 0 deletions tests/unit_tests/meta/is_pointer_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "zll/meta/is_pointer.hpp"
#include "zll/meta/is_same.hpp"

#include <utest.h>

struct test_dummy {};

UTEST(meta_is_pointer, is_pointer) {
ASSERT_TRUE(zll::meta::is_pointer<test_dummy*>::value);
ASSERT_TRUE(zll::meta::is_pointer<test_dummy const* volatile>::value);
ASSERT_TRUE(zll::meta::is_pointer<void*>::value);
ASSERT_TRUE(zll::meta::is_pointer<int*>::value);
ASSERT_TRUE(zll::meta::is_pointer<int**>::value);
ASSERT_TRUE(zll::meta::is_pointer<void (*)()>::value);

ASSERT_FALSE(zll::meta::is_pointer<test_dummy>::value);
ASSERT_FALSE(zll::meta::is_pointer<test_dummy&>::value);
ASSERT_FALSE(zll::meta::is_pointer<int>::value);
ASSERT_FALSE(zll::meta::is_pointer<int[3]>::value);
}

0 comments on commit 1e6426e

Please sign in to comment.