Commit f57cccc9 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Cut FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS

Summary: [Folly] Cut `FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS` since its margin of utility is too small given `folly::is_detected`.

Reviewed By: Mizuchi

Differential Revision: D23371271

fbshipit-source-id: 6db49163d54ffd4d862bb98345d0e71b4d114674
parent ec658b16
...@@ -26,25 +26,6 @@ ...@@ -26,25 +26,6 @@
#include <folly/Portability.h> #include <folly/Portability.h>
#define FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(classname, type_name) \
template <typename TTheClass_> \
struct classname##__folly_traits_impl__ { \
template <typename UTheClass_> \
static constexpr bool test(typename UTheClass_::type_name*) { \
return true; \
} \
template <typename> \
static constexpr bool test(...) { \
return false; \
} \
}; \
template <typename TTheClass_> \
using classname = typename std::conditional< \
classname##__folly_traits_impl__<TTheClass_>::template test<TTheClass_>( \
nullptr), \
std::true_type, \
std::false_type>::type
namespace folly { namespace folly {
template <typename...> template <typename...>
...@@ -363,12 +344,13 @@ FOLLY_INLINE_VARIABLE constexpr bool is_trivially_copyable_v = ...@@ -363,12 +344,13 @@ FOLLY_INLINE_VARIABLE constexpr bool is_trivially_copyable_v =
namespace traits_detail { namespace traits_detail {
#define FOLLY_HAS_TRUE_XXX(name) \ #define FOLLY_HAS_TRUE_XXX(name) \
FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(has_##name, name); \ template <typename T> \
using detect_##name = typename T::name; \
template <class T> \ template <class T> \
struct name##_is_true : std::is_same<typename T::name, std::true_type> {}; \ struct name##_is_true : std::is_same<typename T::name, std::true_type> {}; \
template <class T> \ template <class T> \
struct has_true_##name : std::conditional< \ struct has_true_##name : std::conditional< \
has_##name<T>::value, \ is_detected_v<detect_##name, T>, \
name##_is_true<T>, \ name##_is_true<T>, \
std::false_type>::type {} std::false_type>::type {}
...@@ -444,18 +426,19 @@ struct IsNothrowSwappable ...@@ -444,18 +426,19 @@ struct IsNothrowSwappable
/* using override */ using traits_detail_IsNothrowSwappable::IsNothrowSwappable; /* using override */ using traits_detail_IsNothrowSwappable::IsNothrowSwappable;
template <class T> template <class T>
struct IsRelocatable : std::conditional< struct IsRelocatable
traits_detail::has_IsRelocatable<T>::value, : std::conditional<
traits_detail::has_true_IsRelocatable<T>, is_detected_v<traits_detail::detect_IsRelocatable, T>,
// TODO add this line (and some tests for it) when we traits_detail::has_true_IsRelocatable<T>,
// upgrade to gcc 4.7 // TODO add this line (and some tests for it) when we
// std::is_trivially_move_constructible<T>::value || // upgrade to gcc 4.7
is_trivially_copyable<T>>::type {}; // std::is_trivially_move_constructible<T>::value ||
is_trivially_copyable<T>>::type {};
template <class T> template <class T>
struct IsZeroInitializable struct IsZeroInitializable
: std::conditional< : std::conditional<
traits_detail::has_IsZeroInitializable<T>::value, is_detected_v<traits_detail::detect_IsZeroInitializable, T>,
traits_detail::has_true_IsZeroInitializable<T>, traits_detail::has_true_IsZeroInitializable<T>,
bool_constant<!std::is_class<T>::value>>::type {}; bool_constant<!std::is_class<T>::value>>::type {};
......
...@@ -28,21 +28,6 @@ ...@@ -28,21 +28,6 @@
using namespace folly; using namespace folly;
using namespace std; using namespace std;
namespace {
FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(has_member_type_x, x);
} // namespace
TEST(Traits, has_member_type) {
struct membership_no {};
struct membership_yes {
using x = void;
};
EXPECT_TRUE((is_same<false_type, has_member_type_x<membership_no>>::value));
EXPECT_TRUE((is_same<true_type, has_member_type_x<membership_yes>>::value));
}
struct T1 {}; // old-style IsRelocatable, below struct T1 {}; // old-style IsRelocatable, below
struct T2 {}; // old-style IsRelocatable, below struct T2 {}; // old-style IsRelocatable, below
struct T3 { struct T3 {
......
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