Skip to content

Commit d86590a

Browse files
move semantics also for matrix
1 parent 9b5f7af commit d86590a

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

inst/include/Rcpp/api/meat/Matrix.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ namespace Rcpp{
5353
template <int RTYPE>
5454
Matrix<RTYPE>::Matrix( const Matrix& other) : VECTOR( other.asSexp() ), nrows(other.nrows) {}
5555

56+
57+
template <int RTYPE>
58+
Matrix<RTYPE>::Matrix( Matrix<RTYPE>&& other) : VECTOR(){
59+
RObject::m_sexp = other.m_sexp ;
60+
RCPP_DEBUG_MOVE_CTOR( Matrix, "( %s&& other ), SEXP= <%p>", DEMANGLE(Matrix), m_sexp )
61+
other.m_sexp = R_NilValue ;
62+
VECTOR::update_vector() ;
63+
nrows = other.nrows ;
64+
}
65+
66+
template <int RTYPE>
67+
Matrix<RTYPE>& Matrix<RTYPE>::operator=( Matrix<RTYPE>&& other) {
68+
RCPP_DEBUG_CLASS( Matrix, "::operator=( %s&& )", DEMANGLE(Matrix) )
69+
if( this != &other ){
70+
Rcpp_ReleaseObject(RObject::m_sexp) ;
71+
RObject::m_sexp = other.m_sexp ;
72+
other.m_sexp = R_NilValue ;
73+
VECTOR::update_vector() ;
74+
nrows = other.nrows ;
75+
}
76+
return *this ;
77+
}
78+
79+
5680
template <int RTYPE>
5781
template <bool NA, typename MAT>
5882
Matrix<RTYPE>::Matrix( const MatrixBase<RTYPE,NA,MAT>& other ) : VECTOR( Rf_allocMatrix( RTYPE, other.nrow(), other.ncol() ) ), nrows(other.nrow()) {

inst/include/Rcpp/vector/Matrix.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
//
2-
// Matrix.h: matrices
3-
//
41
// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
2+
// Copyright (C) 2013 Romain Francois
53
//
64
// This file is part of Rcpp11.
75
//
@@ -54,6 +52,8 @@ class Matrix : public Vector<RTYPE>, public MatrixBase<RTYPE,true, Matrix<RTYPE>
5452
Matrix( const int& nrows_, const int& ncols, Iterator start ) ;
5553

5654
Matrix( const Matrix& other) ;
55+
Matrix( Matrix&& other ) ;
56+
Matrix& operator=( Matrix&& other) ;
5757

5858
template <bool NA, typename MAT>
5959
Matrix( const MatrixBase<RTYPE,NA,MAT>& other ) ;

0 commit comments

Comments
 (0)