Rcpp Version 1.1.2
Loading...
Searching...
No Matches
Comparator_With_One_Value.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// LessThan.h: Rcpp R/C++ interface class library -- vector operators
4//
5// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois
6// Copyright (C) 2026 Dirk Eddelbuettel, Romain Francois and IƱaki Ucar
7//
8// This file is part of Rcpp.
9//
10// Rcpp is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 2 of the License, or
13// (at your option) any later version.
14//
15// Rcpp is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
22
23#ifndef Rcpp__sugar__Comparator_With_One_Value_h
24#define Rcpp__sugar__Comparator_With_One_Value_h
25
26namespace Rcpp{
27namespace sugar{
28
29template <int RTYPE, typename Operator, bool NA, typename T>
30class Comparator_With_One_Value : public ::Rcpp::VectorBase< LGLSXP, true, Comparator_With_One_Value<RTYPE,Operator,NA,T> > {
31public:
34 typedef int (Comparator_With_One_Value::*METHOD)(int) const ;
35
44
45 inline int operator[]( R_xlen_t i ) const {
46 return (this->*m)(i) ;
47 }
48
49 inline R_xlen_t size() const { return lhs.size() ; }
50
51private:
52 const VEC_TYPE& lhs ;
55 Operator op ;
56
57 inline int rhs_is_na(int i) const { return rhs ; }
58 inline int rhs_is_not_na(int i) const {
59 STORAGE x = lhs[i] ;
60 return Rcpp::traits::is_na<RTYPE>(x) ? NA_INTEGER : op( x, rhs ) ;
61 }
62
63} ;
64
65
66template <int RTYPE, typename Operator, typename T>
67class Comparator_With_One_Value<RTYPE,Operator,false,T> :
68 public ::Rcpp::VectorBase< RTYPE, true, Comparator_With_One_Value<LGLSXP,Operator,false,T> > {
69
70public:
73 typedef int (Comparator_With_One_Value::*METHOD)(int) const ;
74
83
84 inline int operator[]( R_xlen_t i ) const {
85 return (this->*m)(i) ;
86 }
87
88 inline R_xlen_t size() const { return lhs.size() ; }
89
90private:
91 const VEC_TYPE& lhs ;
94 Operator op ;
95
96 inline int rhs_is_na(int i) const { return rhs ; }
97 inline int rhs_is_not_na(int i) const {
98 return op( lhs[i], rhs ) ;
99 }
100
101} ;
102
103
104} // sugar
105} // Rcpp
106
107
108
109
110
111#endif
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
traits::storage_type< RTYPE >::type STORAGE
Comparator_With_One_Value(const VEC_TYPE &lhs_, STORAGE rhs_)
int(Comparator_With_One_Value::* METHOD)(int) const
bool is_na(typename storage_type< RTYPE >::type)
Definition is_na.h:32
Rcpp API.
Definition algo.h:28