-
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
3 changed files
with
58 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 @@ | ||
#ifndef ZLL_META_TRAITS_ISFUNCTION_HPP | ||
#define ZLL_META_TRAITS_ISFUNCTION_HPP | ||
|
||
#include "zll/meta/integral_constant.hpp" | ||
#include "zll/meta/traits/is_const.hpp" | ||
#include "zll/meta/traits/is_reference.hpp" | ||
|
||
namespace zll { | ||
namespace meta { | ||
|
||
namespace detail { | ||
|
||
template <typename T> | ||
struct is_function_helper { | ||
static const bool value = !(zll::meta::is_const<const T>::value) && !(zll::meta::is_reference<T>::value); | ||
}; | ||
|
||
} // namespace detail | ||
|
||
template <typename T> | ||
struct is_function : zll::meta::bool_constant<detail::is_function_helper<T>::value> {}; | ||
|
||
} // namespace meta | ||
} // namespace zll | ||
|
||
#endif // ZLL_META_TRAITS_ISFUNCTION_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,31 @@ | ||
#include <zll/meta/traits/is_function.hpp> | ||
#include <zll/utils/typeof_macro.hpp> | ||
|
||
#include <utest.h> | ||
|
||
struct test_struct { | ||
int fun() const; | ||
}; | ||
|
||
int test_function(); | ||
|
||
template <typename T> | ||
struct test_trait {}; | ||
template <typename T, typename U> | ||
struct test_trait<U T::*> { | ||
typedef U member_type; | ||
}; | ||
|
||
UTEST(meta_traits_is_function, is_function) { | ||
ASSERT_TRUE((zll::meta::is_function<int(int)>::value)); | ||
ASSERT_TRUE((zll::meta::is_function<ZLL_TYPE_OF(test_function)>::value)); | ||
|
||
typedef test_trait<ZLL_TYPE_OF(&test_struct::fun)>::member_type fun_type; | ||
ASSERT_TRUE((zll::meta::is_function<fun_type>::value)); | ||
} | ||
|
||
UTEST(meta_traits_is_function, is_not_function) { | ||
ASSERT_FALSE((zll::meta::is_function<int>::value)); | ||
ASSERT_FALSE((zll::meta::is_function<test_struct>::value)); | ||
} | ||
|