[Rcpp-commits] r1639 - in pkg/Rcpp/inst/include/Rcpp/sugar: . functions

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 20 09:23:58 CEST 2010


Author: romain
Date: 2010-06-20 09:23:57 +0200 (Sun, 20 Jun 2010)
New Revision: 1639

Modified:
   pkg/Rcpp/inst/include/Rcpp/sugar/SingleLogicalResult.h
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/all.h
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/any.h
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/sapply.h
Log:
forbid conversion of SingleLogicalResult to bool

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/SingleLogicalResult.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/SingleLogicalResult.h	2010-06-20 02:28:24 UTC (rev 1638)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/SingleLogicalResult.h	2010-06-20 07:23:57 UTC (rev 1639)
@@ -25,7 +25,21 @@
 namespace Rcpp{
 namespace sugar{  
 
-template <typename T>
+template <bool> 
+class forbidden_conversion ;
+
+template <> 
+class forbidden_conversion<true>{} ;
+
+template <bool x>
+class conversion_to_bool_is_forbidden : 
+	conversion_to_bool_is_forbidden<x>{
+	public:
+		void touch(){}
+}; 
+
+
+template <bool NA,typename T>
 class SingleLogicalResult {
 public:
 	const static int UNRESOLVED = -5 ;
@@ -58,6 +72,12 @@
 		return Rf_ScalarLogical( result ) ;
 	}
 	
+	operator bool(){
+		conversion_to_bool_is_forbidden<!NA> x ;
+		x.touch() ;
+		return is_true() ;
+	}
+	
 	inline int size(){ return 1 ; }
 	
 private:

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/all.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/all.h	2010-06-20 02:28:24 UTC (rev 1638)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/all.h	2010-06-20 07:23:57 UTC (rev 1639)
@@ -26,9 +26,9 @@
 namespace sugar{
 
 template <typename T>
-class All : public SingleLogicalResult< All<T> >{
+class All : public SingleLogicalResult< true, All<T> >{
 public:
-	typedef SingleLogicalResult< All<T> > PARENT ;
+	typedef SingleLogicalResult< true, All<T> > PARENT ;
 	All( const T& t ) : PARENT() , object(t) {}
 	
 	void apply(){

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/any.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/any.h	2010-06-20 02:28:24 UTC (rev 1638)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/any.h	2010-06-20 07:23:57 UTC (rev 1639)
@@ -26,9 +26,9 @@
 namespace sugar{
 
 template <typename T>
-class Any : public SingleLogicalResult< Any<T> >{
+class Any : public SingleLogicalResult< true, Any<T> >{
 public:
-	typedef SingleLogicalResult< Any<T> > PARENT ;
+	typedef SingleLogicalResult< true , Any<T> > PARENT ;
 	Any( const T& t ) : PARENT() , object(t) {}
 	
 	void apply(){

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/sapply.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/sapply.h	2010-06-20 02:28:24 UTC (rev 1638)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/sapply.h	2010-06-20 07:23:57 UTC (rev 1639)
@@ -27,7 +27,9 @@
 
 template <int RTYPE, bool NA, typename T, typename Function>
 class Sapply : public VectorBase< 
-	Rcpp::traits::r_sexptype_traits<typename ::Rcpp::traits::result_of<Function>::type >::rtype , 
+	Rcpp::traits::r_sexptype_traits<
+		typename ::Rcpp::traits::result_of<Function>::type
+	>::rtype , 
 	true ,
 	Sapply<RTYPE,NA,T,Function>
 > {



More information about the Rcpp-commits mailing list