-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_DETAIL_CONSTRAINTSTYPE_HPP | ||
#define ZLL_META_DETAIL_CONSTRAINTSTYPE_HPP | ||
|
||
namespace zll { | ||
namespace meta { | ||
namespace detail { | ||
|
||
template <typename T> | ||
struct larger_than { | ||
T body[2]; | ||
}; | ||
|
||
typedef char no_type; | ||
typedef larger_than<no_type> yes_type; | ||
|
||
} // namespace detail | ||
} // namespace meta | ||
} // namespace zll | ||
|
||
#endif // ZLL_META_DETAIL_CONSTRAINTSTYPE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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_ISCLASS_HPP | ||
#define ZLL_META_ISCLASS_HPP | ||
|
||
#include "zll/meta/enable_if.hpp" | ||
#include "zll/meta/integral_constant.hpp" | ||
#include "zll/meta/is_union.hpp" | ||
|
||
#include "zll/meta/detail/constraints_type.hpp" | ||
|
||
#include <cstdlib> | ||
|
||
namespace zll { | ||
namespace meta { | ||
|
||
namespace detail { | ||
|
||
struct is_class_helper { | ||
template <typename T> | ||
static typename enable_if<!(is_union<T>::value), yes_type>::type test(int T::*); | ||
|
||
template <typename> | ||
static no_type test(...); | ||
}; | ||
|
||
} // namespace detail | ||
|
||
template <typename T> | ||
struct is_class : bool_constant<(sizeof(detail::is_class_helper::test<T>(NULL)) == sizeof(detail::yes_type))> {}; | ||
|
||
} // namespace meta | ||
} // namespace zll | ||
|
||
#endif // ZLL_META_ISCLASS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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_class.hpp" | ||
|
||
#include <utest.h> | ||
|
||
struct test_struct {}; | ||
class test_class {}; | ||
|
||
union test_union { | ||
class clazz {}; | ||
}; | ||
|
||
UTEST(meta_is_class, is_class) { | ||
ASSERT_TRUE(zll::meta::is_class<test_class>::value); | ||
ASSERT_TRUE(zll::meta::is_class<const test_class>::value); | ||
ASSERT_TRUE(zll::meta::is_class<test_struct>::value); | ||
ASSERT_TRUE(zll::meta::is_class<const test_struct>::value); | ||
|
||
ASSERT_FALSE(zll::meta::is_class<test_struct*>::value); | ||
ASSERT_FALSE(zll::meta::is_class<test_struct&>::value); | ||
ASSERT_FALSE(zll::meta::is_class<test_union>::value); | ||
|
||
ASSERT_TRUE(zll::meta::is_class<test_union::clazz>::value); | ||
} |