Wednesday, 11 September 2013

SFINAE error on VS2013?

SFINAE error on VS2013?

I've been trying just about anything I could think of to get the
_CallWithRightmostArgsInner function to properly fail so that SFINAE could
work properly and with this attempt, VS2013 has given me the error: error
C2039: 'type' : is not a member of 'std::enable_if<false,void>'
Any ideas? Is there an alternative that would be better? The idea here is
that I would like to make a function call to Function provided that
Function takes a number, NumArgs, parameters. The last two variadic
arguments should be forwarded to the function and the result returned.
template <typename Function, int NumArgs>
class SplitParameters {
public:
typedef typename function_traits<Function>::result_type result_type;
template <typename ... RightArgs>
static result_type CallWithRightmostArgs(const Function& call,
RightArgs && ... rightArgs) {
static_assert(sizeof...(RightArgs) >= NumArgs, "Unable to make
function call with fewer than minimum arguments.");
return _CallWithRightmostArgs(call,
std::forward<RightArgs>(rightArgs)...);
}
private:
template <typename ... RightArgs>
static result_type _CallWithRightmostArgs(const Function& call,
RightArgs && ... rightArgs) {
return _CallWithRightmostArgsInner(call,
std::forward<RightArgs>(rightArgs)...);
}
// note the '==' vs '!=' in these two functions. I would assume that
only one could exist
template <typename LeftArg, typename ... RightArgs, typename
std::enable_if<sizeof...(RightArgs) != NumArgs>::type* = 0>
static result_type _CallWithRightmostArgsInner(const Function& call,
LeftArg, RightArgs && ... rightArgs) {
return _CallWithRightmostArgs(call,
std::forward<RightArgs>(rightArgs)...);
}
template <typename LeftArg, typename ... RightArgs, typename
std::enable_if<sizeof...(RightArgs) == NumArgs>::type* = 0>
static result_type _CallWithRightmostArgsInner(const Function& call,
LeftArg, RightArgs && ... rightArgs) {
return call(std::forward<RightArgs>(rightArgs)...);
}
};

No comments:

Post a Comment