Commit 6226f8a2 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Revise is_instantiation_of_v and is_instantiation_of

Summary: [Folly] Revise is_instantiation_of_v as a variable and as eager, and is_instantiation_of as a type and as deferred.

Reviewed By: Mizuchi

Differential Revision: D23367989

fbshipit-source-id: bf6ebd74b8e7758818dfcebd04152e1297bc99e4
parent 8132af20
...@@ -147,20 +147,21 @@ using index_constant = std::integral_constant<std::size_t, I>; ...@@ -147,20 +147,21 @@ using index_constant = std::integral_constant<std::size_t, I>;
namespace detail { namespace detail {
/** // is_instantiation_of_v
* A type trait to check if a given type is an instantiation of a class // is_instantiation_of
* template. //
* // A trait variable and type to check if a given type is an instantiation of a
* Note that this only works with template type parameters. It does not work // class template.
* with non-type template parameters, template template parameters, or alias //
* templates. // Note that this only works with type template parameters. It does not work
*/ // with non-type template parameters, template template parameters, or alias
// templates.
template <template <typename...> class, typename> template <template <typename...> class, typename>
struct is_instantiation_of : std::false_type {}; FOLLY_INLINE_VARIABLE constexpr bool is_instantiation_of_v = false;
template <template <typename...> class C, typename... T>
FOLLY_INLINE_VARIABLE constexpr bool is_instantiation_of_v<C, C<T...>> = true;
template <template <typename...> class C, typename... T> template <template <typename...> class C, typename... T>
struct is_instantiation_of<C, C<T...>> : std::true_type {}; struct is_instantiation_of : bool_constant<is_instantiation_of_v<C, T...>> {};
template <template <typename...> class C, typename T>
constexpr bool is_instantiation_of_v = is_instantiation_of<C, T>::value;
} // namespace detail } // namespace detail
......
...@@ -418,11 +418,16 @@ TEST(Traits, like) { ...@@ -418,11 +418,16 @@ TEST(Traits, like) {
value)); value));
} }
TEST(Traits, is_instantiation_of) { TEST(Traits, is_instantiation_of_v) {
EXPECT_TRUE((detail::is_instantiation_of_v<A, A<int>>)); EXPECT_TRUE((detail::is_instantiation_of_v<A, A<int>>));
EXPECT_FALSE((detail::is_instantiation_of_v<A, B>)); EXPECT_FALSE((detail::is_instantiation_of_v<A, B>));
} }
TEST(Traits, is_instantiation_of) {
EXPECT_TRUE((detail::is_instantiation_of<A, A<int>>::value));
EXPECT_FALSE((detail::is_instantiation_of<A, B>::value));
}
TEST(Traits, is_constexpr_default_constructible) { TEST(Traits, is_constexpr_default_constructible) {
constexpr auto const broken = kGnuc == 7 && !kIsClang; constexpr auto const broken = kGnuc == 7 && !kIsClang;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment