From: Elizabeth Smith Date: Thu, 8 May 2014 15:20:48 +0000 (-0700) Subject: Expression SFINAE fixes in ApplyTuple X-Git-Tag: v0.22.0~552 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2cb63bedc5b9342f2f80491da7e53afd97de1927;p=folly.git 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 --- 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) {