Skip to content

Commit

Permalink
✨ add is_same trait
Browse files Browse the repository at this point in the history
  • Loading branch information
zie87 committed Oct 5, 2023
1 parent 40588e3 commit 9ba7a90
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/zll/meta/is_same.hpp
Original file line number Diff line number Diff line change
@@ -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 <typename T, typename U>
struct is_same : false_type {};

template <typename T>
struct is_same<T, T> : true_type {};

} // namespace meta
} // namespace zll

#endif // ZLL_META_ISSAME_HPP
6 changes: 6 additions & 0 deletions include/zll/type_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef ZLL_TYPETRAITS_HPP
#define ZLL_TYPETRAITS_HPP

#include "zll/meta/is_same.hpp"

#endif // ZLL_TYPETRAITS_HPP
1 change: 1 addition & 0 deletions 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_same_tests.cpp',
'main.cpp',
]

Expand Down
24 changes: 24 additions & 0 deletions tests/unit_tests/meta/is_same_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "zll/meta/is_same.hpp"

#include <utest.h>

struct test_dummy {};
struct test_child : test_dummy {};

UTEST(meta_is_same, compare_same) {
ASSERT_TRUE((zll::meta::is_same<int, int>::value));
ASSERT_TRUE((zll::meta::is_same<char, char>::value));
ASSERT_TRUE((zll::meta::is_same<test_dummy, test_dummy>::value));
ASSERT_TRUE((zll::meta::is_same<test_child, test_child>::value));
ASSERT_TRUE((zll::meta::is_same<test_dummy&, test_dummy&>::value));
ASSERT_TRUE((zll::meta::is_same<test_child&, test_child&>::value));
}

UTEST(meta_is_same, compare_not_same) {
ASSERT_FALSE((zll::meta::is_same<int, char>::value));
ASSERT_FALSE((zll::meta::is_same<char, short>::value));
ASSERT_FALSE((zll::meta::is_same<test_dummy, test_child>::value));
ASSERT_FALSE((zll::meta::is_same<test_child, int>::value));
ASSERT_FALSE((zll::meta::is_same<test_dummy, test_dummy&>::value));
ASSERT_FALSE((zll::meta::is_same<test_dummy*, test_child*>::value));
}

0 comments on commit 9ba7a90

Please sign in to comment.