From: Nicholas Ormrod Date: Fri, 17 Apr 2015 18:54:36 +0000 (-0700) Subject: Revert "Deprecating folly::is_complete" X-Git-Tag: v0.36.0~24 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8c12e8e566b8f10e3b009fd24f97b26fcd85372a;p=folly.git Revert "Deprecating folly::is_complete" 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 --- diff --git a/folly/Traits.h b/folly/Traits.h index 309157c4..58e9418a 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -290,6 +290,34 @@ struct IsOneOf { enum { value = std::is_same::value || IsOneOf::value }; }; +/** + * A traits class to check for incomplete types. + * + * Example: + * + * struct FullyDeclared {}; // complete type + * struct ForwardDeclared; // incomplete type + * + * is_complete::value // evaluates to true + * is_complete::value // evaluates to true + * is_complete::value // evaluates to false + * + * struct ForwardDeclared {}; // declared, at last + * + * is_complete::value // now it evaluates to true + * + * @author: Marcelo Juchem + */ +template +class is_complete { + template struct sfinae {}; + template + constexpr static bool test(sfinae*) { return true; } + template constexpr static bool test(...) { return false; } +public: + constexpr static bool value = test(nullptr); +}; + /* * Complementary type traits for integral comparisons. * diff --git a/folly/test/TraitsTest.cpp b/folly/test/TraitsTest.cpp index 83ffb43d..695e36d6 100644 --- a/folly/test/TraitsTest.cpp +++ b/folly/test/TraitsTest.cpp @@ -110,6 +110,14 @@ TEST(Traits, relational) { EXPECT_FALSE((folly::greater_than(254u))); } +struct CompleteType {}; +struct IncompleteType; +TEST(Traits, is_complete) { + EXPECT_TRUE((folly::is_complete::value)); + EXPECT_TRUE((folly::is_complete::value)); + EXPECT_FALSE((folly::is_complete::value)); +} + int main(int argc, char ** argv) { testing::InitGoogleTest(&argc, argv); gflags::ParseCommandLineFlags(&argc, &argv, true);