Rcpp Version 1.0.14
Loading...
Searching...
No Matches
any.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// any.h: Rcpp R/C++ interface class library -- any
4//
5// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
6//
7// This file is part of Rcpp.
8//
9// Rcpp is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// Rcpp is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22#ifndef Rcpp__sugar__any_h
23#define Rcpp__sugar__any_h
24
25namespace Rcpp{
26namespace sugar{
27
28template <bool NA, typename T>
29class Any : public SingleLogicalResult< true, Any<NA,T> >{
30public:
33 Any( const VEC_TYPE& t ) : PARENT() , object(t) {}
34
35 void apply(){
36 R_xlen_t n = object.size() ;
37 int current = 0 ;
39 for( R_xlen_t i=0 ; i<n ; i++){
40 current = object[i] ;
41 if( current == TRUE ) {
43 return ;
44 }
45 if( Rcpp::traits::is_na<LGLSXP>(current) ) {
47 }
48 }
51 }
52 }
53private:
55} ;
56
57template <typename T>
58class Any<false,T> : public SingleLogicalResult< false, Any<false,T> >{
59public:
62 Any( const VEC_TYPE& t ) : PARENT() , object(t) {}
63
64 void apply(){
65 R_xlen_t n = object.size() ;
67 for( R_xlen_t i=0 ; i<n ; i++){
68 if( object[i] == TRUE ) {
70 return ;
71 }
72 }
73 }
74private:
76} ;
77
78} // sugar
79
80template <bool NA, typename T>
84
85} // Rcpp
86#endif
87
Rcpp::VectorBase< LGLSXP, false, T > VEC_TYPE
Definition any.h:60
SingleLogicalResult< false, Any< false, T > > PARENT
Definition any.h:61
Any(const VEC_TYPE &t)
Definition any.h:62
const VEC_TYPE & object
Definition any.h:75
Rcpp::VectorBase< LGLSXP, NA, T > VEC_TYPE
Definition any.h:31
void apply()
Definition any.h:35
Any(const VEC_TYPE &t)
Definition any.h:33
SingleLogicalResult< true, Any< NA, T > > PARENT
Definition any.h:32
const VEC_TYPE & object
Definition any.h:54
bool is_na< LGLSXP >(int x)
Definition is_na.h:57
Rcpp API.
Definition algo.h:28
bool any(InputIterator first, InputIterator last, const T &value)
Definition algo.h:89
T as(SEXP x)
Definition as.h:151