大佬教程收集整理的这篇文章主要介绍了c – 在Clang vs. GCC与MSVC中的SFINAE和能见度检查 – 这是正确的吗?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
template<class = void> struct is_default_constructible; template<> struct is_default_constructible<> { protected: // Put base typedefs here to avoid pollution struct twoc { char a,b; }; template<bool> struct test { typedef char type; }; template<class T> static T declval(); }; template<> struct is_default_constructible<>::test<true> { typedef twoc type; }; template<class T> struct is_default_constructible : is_default_constructible<> { private: template<class U> static typename test<!!sizeof(::new U())>::type sfinae(U*); template<class U> static char sfinae(...); public: static bool const value = sizeof(sfinae<T>(0)) > 1; };
当我在GCC中测试它(-std = c 03)时,它返回0,因为构造函数是不可见的:
class Test { test(); }; int main() { return is_default_constructible<Test>::value; }
当我在Visual C中测试它时(不同的版本都有相同的行为),我回来1.
当我在Clang中测试它(也是-std = c 03)时,我得到:
error: calling a private constructor of class 'Test' template<class U> static typename test<!!sizeof(::new U())>::type sfinae(U *); ^ note: while substituTing explicitly-specified template arguments into function template 'sfinae' static bool const value = sizeof(sfinae<T>(0)) > 1; ^ note: in instantiation of template class 'is_default_constructible<Test>' requested here return is_default_constructible<Test>::value; ^ error: calling a private constructor of class 'Test' template<class U> static typename test<!!sizeof(::new U())>::type sfinae(U *); ^ note: while substituTing deduced template arguments into function template 'sfinae' [with U = Test] static bool const value = sizeof(sfinae<T>(0)) > 1; ^ note: in instantiation of template class 'is_default_constructible<Test>' requested here return is_default_constructible<Test>::value;
哪个编译器是正确的,为什么?
以上是大佬教程为你收集整理的c – 在Clang vs. GCC与MSVC中的SFINAE和能见度检查 – 这是正确的吗?全部内容,希望文章能够帮你解决c – 在Clang vs. GCC与MSVC中的SFINAE和能见度检查 – 这是正确的吗?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。