C++ SFINAE使用枚举模板参数失败

C++ SFINAE使用枚举模板参数失败,c++,templates,enums,sfinae,C++,Templates,Enums,Sfinae,有人能解释以下行为吗(我正在使用Visual Studio 2010)。 标题: #pragma once #include <boost\utility\enable_if.hpp> using boost::enable_if_c; enum WeekDay {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY}; template<WeekDay DAY> typename enable_

有人能解释以下行为吗(我正在使用Visual Studio 2010)。
标题:

#pragma once
#include <boost\utility\enable_if.hpp>
using boost::enable_if_c;

enum WeekDay {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY};

template<WeekDay DAY>
typename enable_if_c< DAY==SUNDAY, bool >::type goToWork()  {return false;}

template<WeekDay DAY>
typename enable_if_c< DAY!=SUNDAY, bool >::type goToWork()  {return true;}
编辑:也许有人可以用不同的编译器(VisualStudio2010除外)测试一下,看看是否会发生同样的事情,因为它似乎没有任何意义

编辑:我发现这种行为有一个新的“有趣”方面。也就是说,如果我用
==
更改模板参数的直接比较=运算符”与助手结构模板进行比较时,效果良好:

template<WeekDay DAY>
struct Is
{
    static const bool   Sunday = false;
};

template<>
struct Is<SUNDAY>
{
    static const bool   Sunday = true;
};

template<WeekDay DAY>
typename enable_if_c< Is<DAY>::Sunday, bool >::type   goToWork()  {return false;}

template<WeekDay DAY>
typename enable_if_c< !Is<DAY>::Sunday, bool >::type  goToWork()  {return true;}
模板
结构是
{
静态常数布尔周日=假;
};
模板
结构是
{
静态常数布尔周日=真;
};
模板
typename enable_if_c::type goToWork(){return false;}
模板
typename启用\u如果\u c<!Is::Sunday,bool>::键入goToWork(){return true;}
编辑: 顺便说一下,我做了一个bug报告,下面是微软的答案:“这是在尝试升级非类型模板参数时出现的错误。不幸的是,考虑到本版本的资源限制以及可用的变通方法,我们将无法在Visual Studio的下一版本中解决此问题。解决方法是将模板参数类型更改为int。“


(我认为“此版本”指的是Visual Studio 2010)

在GCC 4.2.1中运行良好


看起来VC的模板引擎缺少枚举类型的比较运算符,或者它草率地将枚举转换为int,然后决定严格禁止隐式转换为int(显然0和1除外).

很高兴知道我没有发疯。我还怀疑运算符不知怎么丢失了,因为不仅比较运算符==和!=而且逻辑运算符和&&&| |造成了严重破坏。很抱歉忽略了mac用户。如果能在2017年解决这个问题,那就太好了。。。
error C2770: invalid explicit template argument(s) for 'enable_if_c<DAY!=6,bool>::type goToWork(void)'  
error C2770: invalid explicit template argument(s) for 'enable_if_c<DAY==6,bool>::type goToWork(void)'
template<int DAY>
typename enable_if_c< DAY==SUNDAY, bool >::type goToWork()  {return false;}

template<int DAY>
typename enable_if_c< DAY!=SUNDAY, bool >::type goToWork()  {return true;}
template<WeekDay DAY>  bool goToWork()          {return true;}
template<>             bool goToWork<SUNDAY>()  {return false;}
error C2440: 'specialization' : cannot convert from 'int' to 'const WeekDay'  
Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)  
template<WeekDay DAY>
struct Is
{
    static const bool   Sunday = false;
};

template<>
struct Is<SUNDAY>
{
    static const bool   Sunday = true;
};

template<WeekDay DAY>
typename enable_if_c< Is<DAY>::Sunday, bool >::type   goToWork()  {return false;}

template<WeekDay DAY>
typename enable_if_c< !Is<DAY>::Sunday, bool >::type  goToWork()  {return true;}