Vin*_*ent 3 c++ return-type type-traits operator-keyword c++11
考虑以下功能:
template<class T1, class T2, class T3 = /* SOMETHING */>
T3 f(const T1& x, const T2& y);
Run Code Online (Sandbox Code Playgroud)
我希望T3等于返回类型T1+T2.如何用C++ 11做到这一点?
注意:我不想要结果std::common_type<T1, T2>::type,我想要真正的类型T1+T2,考虑到operator+可以是非成员函数或者可以是成员函数T1.
Man*_*rse 13
通常的方法是decltype和尾随返回类型:
template<class T1, class T2>
auto f(const T1& x, const T2& y) -> decltype(x+y);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
178 次 |
| 最近记录: |