[Rcpp-commits] r4479 - pkg/RcppArmadillo/inst/include

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Sep 13 17:57:55 CEST 2013


Author: romain
Date: 2013-09-13 17:57:55 +0200 (Fri, 13 Sep 2013)
New Revision: 4479

Modified:
   pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h
Log:
version that does not use pointers

Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h	2013-09-13 15:26:28 UTC (rev 4478)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h	2013-09-13 15:57:55 UTC (rev 4479)
@@ -105,20 +105,15 @@
     		public:
     			typedef const typename arma::Mat<T>& const_reference ;
     			
-    			InputParameter( SEXP x_ ) : mat(x_) {
-    				ptr = new arma::Mat<T>( mat.begin(), mat.nrow(), mat.ncol(), false ) ;	
-    			}
+    			InputParameter( SEXP x_ ) : m(x_), mat( m.begin(), m.nrow(), m.ncol(), false ){}
+    			
     			inline operator const_reference(){
-    				return const_cast<const_reference>( *ptr ) ; 	
+    				return mat ; 	
     			}
     			
-    			~InputParameter(){
-    				delete ptr ;
-    			}
-    			
     		private:
-    			Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > mat ;
-    			arma::Mat<T>* ptr ;
+    			Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > m ;
+    			arma::Mat<T> mat ;
     } ;
     
     template <typename T>
@@ -126,20 +121,15 @@
     		public:
     			typedef typename arma::Mat<T>& reference ;
     			
-    			InputParameter( SEXP x_ ) : mat(x_) {
-    				ptr = new arma::Mat<T>( mat.begin(), mat.nrow(), mat.ncol(), false ) ;	
-    			}
+    			InputParameter( SEXP x_ ) : m(x_), mat( m.begin(), m.nrow(), m.ncol(), false ){}
+    			
     			inline operator reference(){
-    				return *ptr ; 	
+    				return mat ; 	
     			}
     			
-    			~InputParameter(){
-    				delete ptr ;
-    			}
-    			
     		private:
-    			Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > mat ;
-    			arma::Mat<T>* ptr ;
+    			Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > m ;
+    			arma::Mat<T> mat ;
     } ;
     
 }



More information about the Rcpp-commits mailing list