c++ - 在 C++ 11 中使用 decltype 和模板进行矩阵加法
问题描述
在 The C++ Programming Language 的第四版中,Stroustrup 博士用一个例子来计算两个矩阵的结果来演示 decltype() 说明符。我的问题是第一部分括号后的箭头运算符 -> 之间的关系。声明的结果是此代码中的引用吗?(以 auto operator+(const ...) 开头的部分
template<typename T, typename U>
auto operator+(const Matrix<T>& a, const Matrix<U>& b)-> Matrix<decltype(T{}+U{})>
{
Matrix<decltype(T{}+U{})> rest;
for (int i=0; i!=a.rows(); ++i)
for (int j=0; j!=a.cols(); ++j)
res(i,j) += a(i,j) + b(i,j);
return res;
}
解决方案
推荐阅读
- python - 将元组的元组转换为具有键值对的字典
- google-chrome-headless - Chrome 无头打印到 PDF 不渲染图像
- c# - 找不到游戏对象的当前位置
- database - 需要一种优化的方式来处理实体组合以提高性能
- python - TypeError:重新加载 Gensim 模型时,'float' 对象不可下标
- algorithm - 过滤数据结构 AND/OR/NOT 的算法(类似于 GraphQL 实现)
- android - Realm android中的求和查询是同步(阻塞)还是异步?
- typescript - 从选择菜单检查值时量角器打字稿问题
- angular - 在 Rxjs 中,如果您将一个值添加到数组中,然后立即将该数组作为可观察对象发出,这是否是一种反模式?
- flutter - 如何在 Flutter Stateless 小部件中切换