From: stryku Date: Fri, 28 Jul 2017 20:05:08 +0000 (-0700) Subject: Prevent IsOneOf unused template specialization instantiation X-Git-Tag: v2017.07.31.00~14 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=160f868c3f824c2abcb11a80d6c3b27a162f3710;p=folly.git Prevent IsOneOf unused template specialization instantiation Summary: Current `IsOneOf` implementation does unnecessary work because it instantiates all of the possible template specializations, even if type is same as the first of the tested ones. E.g. `IsOneOf` will instantiate: ``` IsOneOf IsOneOf IsOneOf IsOneOf ``` With the proposed inheritance, compiler will stop initializing at the first match. Closes https://github.com/facebook/folly/pull/643 Reviewed By: ericniebler Differential Revision: D5482783 Pulled By: yfeldblum fbshipit-source-id: 3d04c750ce72fa9b19b4d0588cccfb396a9e0715 --- diff --git a/folly/Traits.h b/folly/Traits.h index 03442bea..eed02dc6 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -386,8 +386,14 @@ struct Bools { // Lighter-weight than Conjunction, but evaluates all sub-conditions eagerly. template -struct StrictConjunction - : std::is_same, Bools> {}; +struct StrictConjunction + : std::is_same, Bools<(Ts::value || true)...>> {}; + +template +struct StrictDisjunction + : Negation< + std::is_same, Bools<(Ts::value && false)...>> + > {}; } // namespace folly @@ -509,15 +515,8 @@ struct IsRelocatable< std::pair > IsRelocatable::value> {}; // Is T one of T1, T2, ..., Tn? -template -struct IsOneOf { - enum { value = false }; -}; - -template -struct IsOneOf { - enum { value = std::is_same::value || IsOneOf::value }; -}; +template +using IsOneOf = StrictDisjunction...>; /* * Complementary type traits for integral comparisons.