[Rcpp-commits] r1648 - in pkg/Rcpp: . inst/include/Rcpp/sugar/logical

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 21 15:03:39 CEST 2010


Author: romain
Date: 2010-06-21 15:03:38 +0200 (Mon, 21 Jun 2010)
New Revision: 1648

Added:
   pkg/Rcpp/inst/include/Rcpp/sugar/logical/is.h
Modified:
   pkg/Rcpp/TODO
   pkg/Rcpp/inst/include/Rcpp/sugar/logical/logical.h
Log:
added functions is_true, is_false, is_na

Modified: pkg/Rcpp/TODO
===================================================================
--- pkg/Rcpp/TODO	2010-06-21 12:59:45 UTC (rev 1647)
+++ pkg/Rcpp/TODO	2010-06-21 13:03:38 UTC (rev 1648)
@@ -70,36 +70,7 @@
     	IntegerVector xx(20) ;
     	xx[ range(0,9) ] = seq_len(10 ) ;
     
-    o	SingleLogicalResult does not have an operator bool() because of R missing 
-		values. So we need is_true, is_false and is_na for SingleLogicalResult
-		objects so that we can do: 
-		
-		if( is_true( all( x < 5 ) ) ){
-			...
-		}
-    	
-		We can already do 
-		
-		if( all( x < 5 ).is_true() ){
-			...
-		}
-    	
-		but the syntax above seems more natural. maybe not. Or we can add an 
-		operator int() and do this: 
-		
-		if( all( x < 5 ) == TRUE ){
-			...
-		}
-    	
-		not sure what is best. Actually the last version is a bad idea because
-		in R : NA == TRUE is NA
-
 	o	Compound operators: ++,--,+=, -=, ...
-
-	o	operators &&, || and ! for SingleLogicalResult objects, so that we can
-		do things like : 
-		
-		any( x < y ) || all( x > 0 )
 	
 Testing
 

Added: pkg/Rcpp/inst/include/Rcpp/sugar/logical/is.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/logical/is.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/logical/is.h	2010-06-21 13:03:38 UTC (rev 1648)
@@ -0,0 +1,44 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// is.h: Rcpp R/C++ interface class library -- 
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef RCPP_SUGAR_LOGICAL_IS_H
+#define RCPP_SUGAR_LOGICAL_IS_H
+
+namespace Rcpp{
+
+	template <bool NA, typename T>
+	inline bool is_true( const Rcpp::sugar::SingleLogicalResult<NA,T>& x){
+		return x.is_true() ;
+	}
+
+	template <bool NA, typename T>
+	inline bool is_false( const Rcpp::sugar::SingleLogicalResult<NA,T>& x){
+		return x.is_false() ;
+	}
+
+	template <bool NA, typename T>
+	inline bool is_na( const Rcpp::sugar::SingleLogicalResult<NA,T>& x){
+		return x.is_na() ;
+	}
+	
+	
+}
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/logical/logical.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/logical/logical.h	2010-06-21 12:59:45 UTC (rev 1647)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/logical/logical.h	2010-06-21 13:03:38 UTC (rev 1648)
@@ -29,5 +29,6 @@
 #include <Rcpp/sugar/logical/and.h>
 #include <Rcpp/sugar/logical/or.h>
 
+#include <Rcpp/sugar/logical/is.h>
 
 #endif



More information about the Rcpp-commits mailing list