C++ 常量向量上的GCC SFINAE错误?

C++ 常量向量上的GCC SFINAE错误?,c++,gcc,sfinae,C++,Gcc,Sfinae,此代码块通过SFINAE检测std::vector::push_back方法,但在gcc 4.9系列之前的版本中,不适用于constvector,如您所见,请尝试。它仅从4.9系列开始工作。我试图找到解决这个问题的方法,但我找不到。哪些改变解决了它 #include <vector> template <typename Type, typename Return, typename P1, Return (Type::*Pointer)(P1)> struct S1P

此代码块通过SFINAE检测
std::vector::push_back
方法,但在gcc 4.9系列之前的版本中,不适用于constvector,如您所见,请尝试。它仅从4.9系列开始工作。我试图找到解决这个问题的方法,但我找不到。哪些改变解决了它

#include <vector>

template <typename Type, typename Return, typename P1, Return (Type::*Pointer)(P1)> struct S1PMemberMethod { };

template <typename T> struct SMemberMethodChecker
{
    template <typename Type> static char HasReferencePushBackMethod(S1PMemberMethod<Type, void, const typename Type::value_type &, &Type::push_back> *);
    template <typename Type> static long HasReferencePushBackMethod(...);
    template <typename Type> static char HasPushBackMethod(S1PMemberMethod<Type, void, typename Type::value_type, &Type::push_back> *);
    template <typename Type> static long HasPushBackMethod(...);

    static const bool HAS_PUSH_BACK_METHOD = ((sizeof(HasReferencePushBackMethod<T>(0)) == sizeof(char)) || (sizeof(HasPushBackMethod<T>(0)) == sizeof(char)));
};

int main()
{
    // Compiler error when push_back is not detected
    int A[ SMemberMethodChecker< const std::vector<int> >::HAS_PUSH_BACK_METHOD - 1 ];
}
#包括
模板结构S1PMemberMethod{};
模板结构SMemberMethodChecker
{
模板静态字符HasReferencePushBackMethod(S1PMemberMethod*);
模板静态长HasReferencePushBackMethod(…);
模板静态char-HasPushback方法(S1PMemberMethod*);
模板静态长hashpushback方法(…);
静态常量bool有_PUSH_BACK_METHOD=((sizeof(HasReferencePushBackMethod(0))==sizeof(char))| |(sizeof(hashpushbackmethod(0))==sizeof(char));
};
int main()
{
//未检测到push_back时出现编译器错误
INTA[SMemberMethodChecker::具有向后推的方法-1];
}

链接“此联机编译器”链接到编译器资源管理器的默认代码。@Oliv link solvedIn v4.9,带-std=c++11选项,用于编译代码,但不在v4.8中。因此,它编译的事实与语言的更改无关,而是与错误修复或语言支持的完成有关。为它找到文档当然很困难。@OlivC++11 flag不需要它在v4.9上没有它就可以工作。重点只是证明它独立于标准版本。因此,行为的修改并非来自对GCC使用的标准和/或默认标准的修改。如果我知道你,我会放弃寻找这个变化的文档。