namespace {
FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(has_member_type_x, x);
-}
+} // namespace
TEST(Traits, has_member_type) {
struct membership_no {};
struct F4 : T1 {};
namespace folly {
- template <> struct IsRelocatable<T1> : std::true_type {};
- template <> FOLLY_ASSUME_RELOCATABLE(T2);
-}
+template <>
+struct IsRelocatable<T1> : std::true_type {};
+template <>
+FOLLY_ASSUME_RELOCATABLE(T2);
+} // namespace folly
TEST(Traits, scalars) {
EXPECT_TRUE(IsRelocatable<int>::value);
template <typename T, typename... Args>
void testIsRelocatable(Args&&... args) {
- if (!IsRelocatable<T>::value) return;
+ if (!IsRelocatable<T>::value) {
+ return;
+ }
// We use placement new on zeroed memory to avoid garbage subsections
char vsrc[sizeof(T)] = { 0 };
testIsRelocatable<std::vector<char>>(5, 'g');
}
+
+namespace {
+// has_value_type<T>::value is true if T has a nested type `value_type`
+template <class T, class = void>
+struct has_value_type : std::false_type {};
+
+template <class T>
+struct has_value_type<T, folly::void_t<typename T::value_type>>
+ : std::true_type {};
+
+struct some_tag {};
+
+template <typename T>
+struct container {
+ template <class... Args>
+ container(
+ folly::type_t<some_tag, decltype(T(std::declval<Args>()...))>,
+ Args&&...) {}
+};
+} // namespace
+
+TEST(Traits, void_t) {
+ EXPECT_TRUE((::std::is_same<folly::void_t<>, void>::value));
+ EXPECT_TRUE((::std::is_same<folly::void_t<int>, void>::value));
+ EXPECT_TRUE((::std::is_same<folly::void_t<int, short>, void>::value));
+ EXPECT_TRUE(
+ (::std::is_same<folly::void_t<int, short, std::string>, void>::value));
+ EXPECT_TRUE((::has_value_type<std::string>::value));
+ EXPECT_FALSE((::has_value_type<int>::value));
+}
+
+TEST(Traits, type_t) {
+ EXPECT_TRUE((::std::is_same<folly::type_t<float>, float>::value));
+ EXPECT_TRUE((::std::is_same<folly::type_t<float, int>, float>::value));
+ EXPECT_TRUE((::std::is_same<folly::type_t<float, int, short>, float>::value));
+ EXPECT_TRUE(
+ (::std::is_same<folly::type_t<float, int, short, std::string>, float>::
+ value));
+ EXPECT_TRUE((
+ ::std::is_constructible<::container<std::string>, some_tag, std::string>::
+ value));
+ EXPECT_FALSE(
+ (::std::is_constructible<::container<std::string>, some_tag, float>::
+ value));
+}