Skip to content

Commit

Permalink
✨ add is_object trait
Browse files Browse the repository at this point in the history
  • Loading branch information
zie87 committed Oct 6, 2023
1 parent 5c55641 commit 489471d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/zll/meta/is_object.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef ZLL_META_ISOBJECT_HPP
#define ZLL_META_ISOBJECT_HPP

#include "zll/meta/integral_constant.hpp"
#include "zll/meta/is_array.hpp"
#include "zll/meta/is_class.hpp"
#include "zll/meta/is_scalar.hpp"
#include "zll/meta/is_union.hpp"

namespace zll {
namespace meta {

template <typename T>
struct is_object
: bool_constant<is_scalar<T>::value || is_array<T>::value || is_union<T>::value || is_class<T>::value> {};

} // namespace meta
} // namespace zll

#endif // ZLL_META_ISOBJECT_HPP
1 change: 1 addition & 0 deletions include/zll/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "zll/meta/is_floating_point.hpp"
#include "zll/meta/is_integral.hpp"
#include "zll/meta/is_member_pointer.hpp"
#include "zll/meta/is_object.hpp"
#include "zll/meta/is_pointer.hpp"
#include "zll/meta/is_same.hpp"
#include "zll/meta/is_scalar.hpp"
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ unit_tests_srcs = [
'meta/is_floating_point_tests.cpp',
'meta/is_integral_tests.cpp',
'meta/is_member_pointer_tests.cpp',
'meta/is_object_tests.cpp',
'meta/is_pointer_tests.cpp',
'meta/is_same_tests.cpp',
'meta/is_scalar_tests.cpp',
Expand Down
32 changes: 32 additions & 0 deletions tests/unit_tests/meta/is_object_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "zll/meta/is_object.hpp"

#include <utest.h>

struct test_struct {
int val;
};

enum test_enum {};

UTEST(meta_is_object, is_object) {
ASSERT_TRUE(zll::meta::is_object<int>::value);
ASSERT_TRUE(zll::meta::is_object<int*>::value);
ASSERT_TRUE(zll::meta::is_object<test_struct>::value);
ASSERT_TRUE(zll::meta::is_object<test_struct*>::value);
ASSERT_TRUE(zll::meta::is_object<int (*)()>::value);
}

UTEST(meta_is_object, is_not_object) {
ASSERT_FALSE(zll::meta::is_object<void>::value);
ASSERT_FALSE(zll::meta::is_object<int&>::value);
ASSERT_FALSE(zll::meta::is_object<char*&>::value);
ASSERT_FALSE(zll::meta::is_object<test_struct&>::value);
ASSERT_FALSE(zll::meta::is_object<int()>::value);
ASSERT_FALSE(zll::meta::is_object<void(&)()>::value);
}

0 comments on commit 489471d

Please sign in to comment.