// --- 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'루프 내부에서 중요합니다.
''throw() '대신 ['noexcept'] (http://en.cppreference.com/w/cpp/language/noexcept_spec)를 사용하십시오. – 0x499602D2
yhm, 확인. 때문에? –
@gumtree : C++에서 동적 예외 사양이 더 이상 사용되지 않습니다. –