【发布时间】:2013-06-09 20:02:49
【问题描述】:
使用decltype 我可以执行以下操作:
template <typename T1, typename T2>
auto sum(T1 const & t1, T2 const & T2)
-> decltype(t1+t2)
{ /* ... */ }
但是,在我的情况下,我需要在没有 T1 和 T2 类型的实例的情况下找出加法的类型。具体来说:
template <typename ValueType>
class Matrix
{
/* ... */
public:
template <typename CompatibleType>
auto operator+(Matrix<CompatibleType> const & other)
-> Matrix<decltype(ValueType+CompatibleType)>
{ /* ... */ }
};
当然,decltype(ValueType+CompatibleType) 不能这样工作。有什么办法可以实现吗?
【问题讨论】:
-
查看
std::declval。