From: Yedidya Feldblum Date: Fri, 27 Oct 2017 02:35:23 +0000 (-0700) Subject: type_t, a generalization of void_t X-Git-Tag: v2017.10.30.00~10 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7ec1449d644773aacec801e473ca84438d1d0dec;p=folly.git type_t, a generalization of void_t Summary: [Folly] `type_t`, a generalization of `void_t`. Reviewed By: ericniebler Differential Revision: D6082913 fbshipit-source-id: f9557b5da1f6684b12d570b6c1bd52c102cb0703 --- diff --git a/folly/Traits.h b/folly/Traits.h index d1ab157a..ebf69acf 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -156,10 +156,26 @@ template using _t = typename T::type; /** + * type_t + * + * A type alias for the first template type argument. `type_t` is useful for + * controlling class-template and function-template partial specialization. + * + * Example: + * + * template + * class Container { + * public: + * template + * Container( + * type_t()...))>, + * Args&&...); + * }; + * * void_t * * A type alias for `void`. `void_t` is useful for controling class-template - * partial specialization. + * and function-template partial specialization. * * Example: * @@ -205,13 +221,16 @@ using _t = typename T::type; namespace traits_detail { template -struct void_t_ { - using type = void; +struct type_t_ { + template + using apply = T; }; } // namespace traits_detail +template +using type_t = typename traits_detail::type_t_::template apply; template -using void_t = _t>; +using void_t = type_t; /** * IsRelocatable::value describes the ability of moving around diff --git a/folly/test/TraitsTest.cpp b/folly/test/TraitsTest.cpp index b0214d46..bfb3f7a7 100644 --- a/folly/test/TraitsTest.cpp +++ b/folly/test/TraitsTest.cpp @@ -229,6 +229,16 @@ struct has_value_type : std::false_type {}; template struct has_value_type> : std::true_type {}; + +struct some_tag {}; + +template +struct container { + template + container( + folly::type_t()...))>, + Args&&...) {} +}; } // namespace TEST(Traits, void_t) { @@ -240,3 +250,18 @@ TEST(Traits, void_t) { EXPECT_TRUE((::has_value_type::value)); EXPECT_FALSE((::has_value_type::value)); } + +TEST(Traits, type_t) { + EXPECT_TRUE((::std::is_same, float>::value)); + EXPECT_TRUE((::std::is_same, float>::value)); + EXPECT_TRUE((::std::is_same, float>::value)); + EXPECT_TRUE( + (::std::is_same, float>:: + value)); + EXPECT_TRUE(( + ::std::is_constructible<::container, some_tag, std::string>:: + value)); + EXPECT_FALSE( + (::std::is_constructible<::container, some_tag, float>:: + value)); +}