// --- Move constructor
Matrix(Matrix&& other) throw() : data_(other.data_), Rows_(other.Rows_), Columns_(other.Columns_) { other.Rows_ = other.Columns_ = 0; other.data_ = nullptr; }
// --- Move assignment
Matrix & operator=(Matrix&& other) throw() {
using std::swap;
swap(Rows_, other.Rows_);
swap(Columns_, other.Columns_);
swap(data_, other.data_);
return *this; }
MultiplyAdd
执行:
template <class T>
Matrix<T> MultiplyAdd(const T a,const Matrix<T> &x,const T b) {
Matrix<T> out(a*x+b);
return out; }
template <class T>
Matrix<T> MultiplyAdd(const Matrix<T> a,const Matrix<T> &x,const T b) {
Matrix<T> out(a*x+b);
return out; }
int main(){
Matrix<> x = // some initialization
auto&& temp_auto = MultiplyAdd(a,x,b);
for (int i = 1; i < N-1; i++) {
temp_auto = MultiplyAdd(temp_auto,temp2,b); }
return 0;
}
问题:auto
在最后一个代码片段中使用关键字会避免创建临时对象吗?在“for”循环之前和更重要的是。