Commit 5839c1b4 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Sara Golemon

An has_member_type macro.

Summary: [Folly] An has_member_type macro.

Reviewed By: @juchem

Differential Revision: D2229775
parent 91343de6
......@@ -432,6 +432,16 @@ FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::function);
// Boost
FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(boost::shared_ptr);
#define FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(classname, type_name) \
template <typename T> \
struct classname { \
template <typename C> \
constexpr static bool test(typename C::type_name*) { return true; } \
template <typename> \
constexpr static bool test(...) { return false; } \
constexpr static bool value = test<T>(nullptr); \
}
#define FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, cv_qual) \
template <typename TTheClass_, typename RTheReturn_, typename... TTheArgs_> \
class classname<TTheClass_, RTheReturn_(TTheArgs_...) cv_qual> { \
......
......@@ -110,6 +110,15 @@ TEST(Traits, relational) {
EXPECT_FALSE((folly::greater_than<uint8_t, 255u, uint8_t>(254u)));
}
struct membership_no {};
struct membership_yes { using x = void; };
FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(has_member_type_x, x);
TEST(Traits, has_member_type) {
EXPECT_FALSE(bool(has_member_type_x<membership_no>::value));
EXPECT_TRUE(bool(has_member_type_x<membership_yes>::value));
}
int main(int argc, char ** argv) {
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment