C++ 键入traits以从操作员处获得提升结果

C++ 键入traits以从操作员处获得提升结果,c++,templates,typetraits,C++,Templates,Typetraits,列出C++的隐式类型转换。 所以问题是,有没有一种类型特征可以做到这一点?类似于 template <typename T, typename J> struct promotion_type { typedef decltype(operator+(const T&,const J&)) type; }; )关于decltype(std::declval()+std::declval())?很有趣……我只是用它来验证std::common\u类型不够好。@Ma

列出C++的隐式类型转换。 所以问题是,有没有一种类型特征可以做到这一点?类似于

template <typename T, typename J>
struct promotion_type
{
  typedef decltype(operator+(const T&,const J&)) type;
};

)

关于
decltype(std::declval()+std::declval())

很有趣……我只是用它来验证std::common\u类型不够好。@MadScienceDreams唯一的区别是bool、char和short都是通过
+
提升为int的,但如果T==J,则不按公共_类型。公共_类型的参考实现是
decltype(true?declval():declval())
/home/user/source/testdir/main.cpp:97:51: error: there are no arguments to 'operator+' that depend on a template parameter, so a declaration of 'operator+' must be available [-fpermissive]
   typedef decltype(operator+(const T&,const J&)) type;
                                               ^
/home/user/source/testdir/main.cpp:97:51: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)