SFINAE std::enable_if fails in visual studio 2015

青春壹個敷衍的年華 提交于 2020-01-15 02:54:04

问题


I was trying to port an open sourced project from linux to window, there are some code that compiles perfectly in linux using either g++ or clang++, but I cannot compile it under MSVC 2015, could anyone tell me how to fix it or how to get around it? I appreciate very much for your help!!!

Here is the code (I have simplified it so you can focus on the key stuff)

template <typename T, class IsMatch = void>
class vc_hashkey
{
public:
    static constexpr bool holds_value() { return false; }
};

template <typename T>
class vc_hashkey<T, typename std::enable_if<std::is_integral<T>::value>::type>
{
public:
    static constexpr bool holds_value() { return true; }
};

template <typename T, class IsMatch = void>
class vc_hashkey_and_value
{
};

template <typename T>
class vc_hashkey_and_value<T, typename std::enable_if<vc_hashkey<T>::holds_value()>::type>
{
};

That's it, I did not even used these code pieces in my main function. When I tried to compile, the msvc 2015 update RC1 compiler gives me compile errors on the partial specialization of the class vc_hashkey_and_value, saying:

C2039 'type': is not a member of 'std::enable_if<'false, void>'

C2146 syntax error: missing '>' before identifier 'type'

C2064 term does not evaluate to a function taking 0 arguments

Is this a MSVC compiler error, thanks for helping me!!!

来源:https://stackoverflow.com/questions/33591226/sfinae-stdenable-if-fails-in-visual-studio-2015

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!