[Rcpp-commits] r2171 - pkg/Rcpp/inst/include/Rcpp/vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Sep 25 11:49:44 CEST 2010


Author: romain
Date: 2010-09-25 11:49:44 +0200 (Sat, 25 Sep 2010)
New Revision: 2171

Modified:
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
Log:
trying to leverage std::copy when possible

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-09-25 09:17:46 UTC (rev 2170)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-09-25 09:49:44 UTC (rev 2171)
@@ -94,14 +94,25 @@
     
 private:
 	
-	template <bool NA, typename VEC>
-    void import_expression( const VectorBase<RTYPE,NA,VEC>& other, int n ){
-    	iterator start = begin() ; 
+    template <bool NA, typename VEC>
+    inline void import_expression__iterator( const VectorBase<RTYPE,NA,VEC>& other, int n, Rcpp::traits::true_type ){
+        const VEC& ref = other.get_ref() ;
+		std::copy( ref.begin(), ref.end(), begin() ) ;
+	}
+    
+    template <bool NA, typename VEC>
+    inline void import_expression__iterator( const VectorBase<RTYPE,NA,VEC>& other, int n, Rcpp::traits::false_type ){
+        iterator start = begin() ; 
 		const VEC& ref = other.get_ref() ;
     	for( int i=0; i<n; i++, ++start){
 			*start = ref[i] ;
 		}
     }
+    
+    template <bool NA, typename VEC>
+    inline void import_expression( const VectorBase<RTYPE,NA,VEC>& other, int n ){
+    	import_expression__iterator<NA,VEC>( other, n, typename Rcpp::traits::has_iterator<VEC>::type( ) ) ;
+    }
 
     template <typename T>
     inline void fill_or_generate( const T& t){



More information about the Rcpp-commits mailing list