type_t, a generalization of void_t
[folly.git] / folly / test / TraitsTest.cpp
index b0214d4624b1d4239d979f62c7f357fa4d752d91..bfb3f7a73dcd3c634c1516d595c93a5b68607c33 100644 (file)
@@ -229,6 +229,16 @@ 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) {
@@ -240,3 +250,18 @@ TEST(Traits, void_t) {
   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));
+}