Revert "Deprecating folly::is_complete"
authorNicholas Ormrod <njormrod@fb.com>
Fri, 17 Apr 2015 18:54:36 +0000 (11:54 -0700)
committerAlecs King <int@fb.com>
Mon, 27 Apr 2015 23:45:41 +0000 (16:45 -0700)
Summary: This reverts commit 42add531d4bdb1f95c40e41981f908a1b70865fb.

Test Plan: n/a

Reviewed By: andrewjcg@fb.com

Subscribers: folly-diffs@, yfeldblum, chalfant

FB internal diff: D2002345

Tasks: 6804947

Signature: t1:2002345:1429296810:7db71fe4748d5c71f0f0486751ee426c2cdff653

folly/Traits.h
folly/test/TraitsTest.cpp

index 309157c4dfadcf952faddc8284bf004f07a401ac..58e9418a46f5cb9be8807fcd32fad9f0ab01b8aa 100644 (file)
@@ -290,6 +290,34 @@ struct IsOneOf<T, T1, Ts...> {
   enum { value = std::is_same<T, T1>::value || IsOneOf<T, Ts...>::value };
 };
 
+/**
+ * A traits class to check for incomplete types.
+ *
+ * Example:
+ *
+ *  struct FullyDeclared {}; // complete type
+ *  struct ForwardDeclared; // incomplete type
+ *
+ *  is_complete<int>::value // evaluates to true
+ *  is_complete<FullyDeclared>::value // evaluates to true
+ *  is_complete<ForwardDeclared>::value // evaluates to false
+ *
+ *  struct ForwardDeclared {}; // declared, at last
+ *
+ *  is_complete<ForwardDeclared>::value // now it evaluates to true
+ *
+ * @author: Marcelo Juchem <marcelo@fb.com>
+ */
+template <typename T>
+class is_complete {
+  template <unsigned long long> struct sfinae {};
+  template <typename U>
+  constexpr static bool test(sfinae<sizeof(U)>*) { return true; }
+  template <typename> constexpr static bool test(...) { return false; }
+public:
+  constexpr static bool value = test<T>(nullptr);
+};
+
 /*
  * Complementary type traits for integral comparisons.
  *
index 83ffb43dfea9887fb23cb3362a5d24116b80162b..695e36d6506b475f03e9b24265831103fcfa0ec8 100644 (file)
@@ -110,6 +110,14 @@ TEST(Traits, relational) {
   EXPECT_FALSE((folly::greater_than<uint8_t, 255u, uint8_t>(254u)));
 }
 
+struct CompleteType {};
+struct IncompleteType;
+TEST(Traits, is_complete) {
+  EXPECT_TRUE((folly::is_complete<int>::value));
+  EXPECT_TRUE((folly::is_complete<CompleteType>::value));
+  EXPECT_FALSE((folly::is_complete<IncompleteType>::value));
+}
+
 int main(int argc, char ** argv) {
   testing::InitGoogleTest(&argc, argv);
   gflags::ParseCommandLineFlags(&argc, &argv, true);