From 2cb63bedc5b9342f2f80491da7e53afd97de1927 Mon Sep 17 00:00:00 2001 From: Elizabeth Smith Date: Thu, 8 May 2014 08:20:48 -0700 Subject: [PATCH] Expression SFINAE fixes in ApplyTuple Summary: MSVC does not support Expression SFINAE http://stackoverflow.com/questions/12654067 this is a very nice c++11 feature that makes for some nice clean templating But of course MSVC can't have nice things - it partially implements this when it feels like it, so some will work and some will need the nonsense @override-unit-failures There will be more of these little template helper fixes - they make the code a bit more complex but don't actually change anything when compiled The accompanying fix in the test also does nothing but work around an MSVC compiler bug where it loses it's mind over the global namespace Test Plan: fbconfig -r folly && fbmake runtests Reviewed By: delong.j@fb.com FB internal diff: D1312700 --- folly/ApplyTuple.h | 18 ++++++++++++++---- folly/test/ApplyTupleTest.cpp | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/folly/ApplyTuple.h b/folly/ApplyTuple.h index 3fe30c3d..6fe6093d 100644 --- a/folly/ApplyTuple.h +++ b/folly/ApplyTuple.h @@ -51,13 +51,24 @@ struct DerefSize : std::tuple_size::type> {}; +template struct ExprDoUnpack { + enum { + value = sizeof...(Unpacked) < DerefSize::value + }; +}; + +template struct ExprIsUnpacked { + enum { + value = sizeof...(Unpacked) == DerefSize::value + }; +}; + // CallTuple recursively unpacks tuple arguments so we can forward // them into the function. template struct CallTuple { template - static typename std::enable_if< - (sizeof...(Unpacked) < DerefSize::value), + static typename std::enable_if::value, Ret >::type call(const F& f, Tuple&& t, Unpacked&&... unp) { typedef typename std::tuple_element< @@ -71,8 +82,7 @@ struct CallTuple { } template - static typename std::enable_if< - (sizeof...(Unpacked) == DerefSize::value), + static typename std::enable_if::value, Ret >::type call(const F& f, Tuple&& t, Unpacked&&... unp) { return makeCallable(f)(std::forward(unp)...); diff --git a/folly/test/ApplyTupleTest.cpp b/folly/test/ApplyTupleTest.cpp index 0f831942..7ddac05f 100644 --- a/folly/test/ApplyTupleTest.cpp +++ b/folly/test/ApplyTupleTest.cpp @@ -21,6 +21,10 @@ #include +// this placates visual studio stupidity - see +// http://stackoverflow.com/questions/5503901 +namespace {} + namespace { void func(int a, int b, double c) { -- 2.34.1