Commit 2cb63bed authored by Elizabeth Smith's avatar Elizabeth Smith Committed by Dave Watson

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
parent c31b528b
......@@ -51,13 +51,24 @@ struct DerefSize
: std::tuple_size<typename std::remove_reference<Tuple>::type>
{};
template<class Tuple, class ...Unpacked> struct ExprDoUnpack {
enum {
value = sizeof...(Unpacked) < DerefSize<Tuple>::value
};
};
template<class Tuple, class ...Unpacked> struct ExprIsUnpacked {
enum {
value = sizeof...(Unpacked) == DerefSize<Tuple>::value
};
};
// CallTuple recursively unpacks tuple arguments so we can forward
// them into the function.
template<class Ret>
struct CallTuple {
template<class F, class Tuple, class ...Unpacked>
static typename std::enable_if<
(sizeof...(Unpacked) < DerefSize<Tuple>::value),
static typename std::enable_if<ExprDoUnpack<Tuple, Unpacked...>::value,
Ret
>::type call(const F& f, Tuple&& t, Unpacked&&... unp) {
typedef typename std::tuple_element<
......@@ -71,8 +82,7 @@ struct CallTuple {
}
template<class F, class Tuple, class ...Unpacked>
static typename std::enable_if<
(sizeof...(Unpacked) == DerefSize<Tuple>::value),
static typename std::enable_if<ExprIsUnpacked<Tuple, Unpacked...>::value,
Ret
>::type call(const F& f, Tuple&& t, Unpacked&&... unp) {
return makeCallable(f)(std::forward<Unpacked>(unp)...);
......
......@@ -21,6 +21,10 @@
#include <memory>
// this placates visual studio stupidity - see
// http://stackoverflow.com/questions/5503901
namespace {}
namespace {
void func(int a, int b, double c) {
......
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