[Rcpp-commits] r2789 - in pkg/Rcpp: . inst/include/Rcpp/vector inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 13 18:34:38 CET 2010


Author: romain
Date: 2010-12-13 18:34:38 +0100 (Mon, 13 Dec 2010)
New Revision: 2789

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
   pkg/Rcpp/inst/unitTests/runit.Vector.R
Log:
fix strange bool conversion reported by Daniel Saban?\195?\169s Bov?\195?\169 on Rcpp-devel

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-12-13 01:50:40 UTC (rev 2788)
+++ pkg/Rcpp/ChangeLog	2010-12-13 17:34:38 UTC (rev 2789)
@@ -1,3 +1,9 @@
+2010-12-13  Romain Francois <romain at r-enthusiasts.com>
+
+    * inst/include/Rcpp/vector/string_proxy.h: List::Proxy did not convert
+    bool correctly, reported on Rcpp-devel by 
+    Daniel Sabanés Bové <daniel.sabanesbove at ifspm.uzh.ch>
+
 2010-12-12  Romain Francois <romain at r-enthusiasts.com>
 
     * R/SHLIB.R: new unexported R function SHLIB, small wrapper around 

Modified: pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h	2010-12-13 01:50:40 UTC (rev 2788)
+++ pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h	2010-12-13 17:34:38 UTC (rev 2789)
@@ -253,20 +253,26 @@
 	               
 			template <typename T>
 			generic_proxy& operator=( const T& rhs){
-				set( wrap(rhs) ) ;
+				set(wrap(rhs)) ;
 				return *this; 
 			}
 			
-			operator SEXP() const { return get() ; }
+			operator SEXP() const { 
+			    return get() ;
+			}
 			
 			template <typename U> operator U() const {
-				return ::Rcpp::as<U>( get() ) ;
+				return ::Rcpp::as<U>(get()) ;
 			}
 			
+			operator bool() const {
+			    return ::Rcpp::as<bool>(get()) ;
+			}
+			
 			void swap(generic_proxy& other){
-				SEXP tmp = PROTECT( get() ) ;
+				SEXP tmp = PROTECT(get()) ;
 				set( other.get() ) ;
-				other.set( tmp ) ;
+				other.set(tmp) ;
 				UNPROTECT(1) ;
 			}
 			

Modified: pkg/Rcpp/inst/unitTests/runit.Vector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Vector.R	2010-12-13 01:50:40 UTC (rev 2788)
+++ pkg/Rcpp/inst/unitTests/runit.Vector.R	2010-12-13 17:34:38 UTC (rev 2789)
@@ -569,6 +569,14 @@
 	            		) ;
 	            	
 	            	'
+	            ), 
+	            "List_extract" = list( 
+	                signature( x = "list" ), 
+	                '
+	                    List input(x) ;
+	                    bool a = input[0] ;
+	                    return wrap(a) ;
+	                '
 	            )
 
                 
@@ -1201,4 +1209,8 @@
 		), msg = "complex binary operators" )
 }
 
-
+test.ComplexVector.binary.operators <- function(){
+	fun <- .rcpp.Vector$List_extract
+    checkEquals( fun(list(TRUE)), TRUE )
+    checkEquals( fun(list(FALSE)), FALSE )
+}



More information about the Rcpp-commits mailing list