VS2010 Compiler Bug
- 
					
					
					
					
 #include <iostream> #include <type_traits> using namespace std; struct Vector{}; struct SubVector{}; struct StrangeVector{}; template<class T> struct is_vector_type : false_type{}; template<> struct is_vector_type<Vector> : true_type{}; template<> struct is_vector_type<SubVector> : true_type{}; template<> struct is_vector_type<StrangeVector> : true_type{}; template <typename T1, typename T2> typename std::enable_if<is_vector_type<T1>::value && is_vector_type<T2>::value, const Vector>::type operator +(const T1 &t1, const T2 &t2){ cout << "Addiere 2 Vektoren\n"; return Vector(); } template <typename T1, typename T2> typename std::enable_if<is_vector_type<T1>::value && is_arithmetic<T2>::value, const Vector>::type operator *(const T1 &t1, const T2 &t2){ cout << "Multipliziere einen Vektor mit einem zahlartigen Datentyp\n"; return Vector(); } template <typename T1, typename T2> typename std::enable_if<is_arithmetic<T1>::value && is_vector_type<T2>::value, const Vector>::type operator *(const T1 &t1, const T2 &t2){ cout << "Multipliziere einen zahlartigen Datentyp mit einem Vektor auf clevere/faule Weise!\n"; return t2 * t1; } int main(){ 6 * Vector(); }Idone sagt alles ok. VS2010 Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 sagt: 1>ClCompile: 1> testbasics.cpp 1>testbasics.cpp(32): error C2893: Failed to specialize function template 'std::enable_if<std::tr1::is_arithmetic<_Ty>::value&&is_vector_type<T2>::value,const Vector>::type operator *(const T1 &,const T2 &)' 1> With the following template arguments: 1> 'Vector' 1> 'int' 1> testbasics.cpp(36) : see reference to function template instantiation 'const Vector operator *<int,Vector>(const T1 &,const T2 &)' being compiled 1> with 1> [ 1> T1=int, 1> T2=Vector 1> ] 1>testbasics.cpp(32): error C2893: Failed to specialize function template 'std::enable_if<is_vector_type<T>::value&&is_vector_type<T2>::value,const Vector>::type operator *(const T1 &,const T2 &)' 1> With the following template arguments: 1> 'Vector' 1> 'int' 1>testbasics.cpp(32): error C2676: binary '*' : 'const Vector' does not define this operator or a conversion to a type acceptable to the predefined operator 1> 1>Build FAILED.Interessant ist Zeile 13 wo er *is_vector_type<T>::value&&is_vector_type<T2>::value,const Vector>::type operator ** sagt, obwohl das im Code nicht steht. 
 Weiterhin interessant ist, dass es kompiliert, wenn man das Template für operator + wegnimmt.Wahrscheinlich interessiert sich niemand für einen 3 Jahre alten Compilerbug  
 
- 
					
					
					
					
 Ohne es mit genauer angeschaut zu haben: VS 2012 kompilierts ohne Probleme. 
 
