Rcpp Version 0.12.12
mapply_2.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2 //
3 // mapply_2.h: Rcpp R/C++ interface class library -- mapply_2
4 //
5 // Copyright (C) 2012 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__mapply_2_h
23 #define Rcpp__sugar__mapply_2_h
24 
25 namespace Rcpp{
26 namespace sugar{
27 
28 template <int RTYPE,
29  bool NA_1, typename T_1,
30  bool NA_2, typename T_2,
31  typename Function
32 >
33 class Mapply_2 : public VectorBase<
34  Rcpp::traits::r_sexptype_traits<
35  typename ::Rcpp::traits::result_of<Function>::type
36  >::rtype ,
37  true ,
38  Mapply_2<RTYPE,NA_1,T_1,NA_2,T_2,Function>
39 > {
40 public:
41  typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
42 
43  Mapply_2( const T_1& vec_1_, const T_2& vec_2_, Function fun_ ) :
44  vec_1(vec_1_), vec_2(vec_2_), fun(fun_){}
45 
46  inline result_type operator[]( R_xlen_t i ) const {
47  return fun( vec_1[i], vec_2[i] );
48  }
49  inline R_xlen_t size() const { return vec_1.size() ; }
50 
51 private:
52  const T_1& vec_1 ;
53  const T_2& vec_2 ;
55 } ;
56 
57 template <int RTYPE,
58  bool NA_1, typename T_1,
59  typename PRIM_2 ,
60  typename Function
61 >
63  VectorBase<
64  Rcpp::traits::r_sexptype_traits<
65  typename ::Rcpp::traits::result_of<Function>::type
66  >::rtype ,
67  true ,
68  Mapply_2_Vector_Primitive<RTYPE,NA_1,T_1,PRIM_2,Function>
69  >
70 {
71 public:
72  typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
73 
74  Mapply_2_Vector_Primitive( const T_1& vec_1_, PRIM_2 prim_2_, Function fun_ ) :
75  vec_1(vec_1_), prim_2(prim_2_), fun(fun_){}
76 
77  inline result_type operator[]( R_xlen_t i ) const {
78  return fun( vec_1[i], prim_2 );
79  }
80  inline R_xlen_t size() const { return vec_1.size() ; }
81 
82 private:
83  const T_1& vec_1 ;
84  PRIM_2 prim_2 ;
86 } ;
87 
88 template <int RTYPE,
89  typename PRIM_1,
90  bool NA_2, typename T_2,
91  typename Function
92 >
94  VectorBase<
95  Rcpp::traits::r_sexptype_traits<
96  typename ::Rcpp::traits::result_of<Function>::type
97  >::rtype ,
98  true ,
99  Mapply_2_Primitive_Vector<RTYPE,PRIM_1,NA_2,T_2,Function>
100  >
101 {
102 public:
103  typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
104 
105  Mapply_2_Primitive_Vector( PRIM_1 prim_1_, const T_2& vec_2_, Function fun_ ) :
106  prim_1(prim_1_), vec_2(vec_2_), fun(fun_){}
107 
108  inline result_type operator[]( R_xlen_t i ) const {
109  return fun( prim_1, vec_2[i] );
110  }
111  inline R_xlen_t size() const { return vec_2.size() ; }
112 
113 private:
114  PRIM_1 prim_1 ;
115  const T_2& vec_2 ;
117 } ;
118 
119 
120 
121 } // sugar
122 
123 
124 template <int RTYPE, bool NA_1, typename T_1, bool NA_2, typename T_2, typename Function >
128 }
129 
130 template <int RTYPE, bool NA_1, typename T_1, typename Function >
134 }
135 
136 template <int RTYPE, bool NA_2, typename T_2, typename Function >
140 }
141 
142 
143 
144 } // Rcpp
145 
146 #endif
const T_1 & vec_1
Definition: mapply_2.h:52
::Rcpp::traits::result_of< Function >::type result_type
Definition: mapply_2.h:41
Mapply_2_Vector_Primitive(const T_1 &vec_1_, PRIM_2 prim_2_, Function fun_)
Definition: mapply_2.h:74
const T_2 & vec_2
Definition: mapply_2.h:53
VECTOR & get_ref()
Definition: VectorBase.h:37
R_xlen_t size() const
Definition: mapply_2.h:49
Function_Impl< PreserveStorage > Function
Definition: Function.h:114
result_type operator[](R_xlen_t i) const
Definition: mapply_2.h:77
result_type operator[](R_xlen_t i) const
Definition: mapply_2.h:108
sugar::Mapply_2< RTYPE, NA_1, T_1, NA_2, T_2, Function > mapply(const Rcpp::VectorBase< RTYPE, NA_1, T_1 > &t1, const Rcpp::VectorBase< RTYPE, NA_2, T_2 > &t2, Function fun)
Definition: mapply_2.h:126
::Rcpp::traits::result_of< Function >::type result_type
Definition: mapply_2.h:103
Mapply_2(const T_1 &vec_1_, const T_2 &vec_2_, Function fun_)
Definition: mapply_2.h:43
Mapply_2_Primitive_Vector(PRIM_1 prim_1_, const T_2 &vec_2_, Function fun_)
Definition: mapply_2.h:105
::Rcpp::traits::result_of< Function >::type result_type
Definition: mapply_2.h:72
Rcpp API.
Definition: algo.h:28
result_type operator[](R_xlen_t i) const
Definition: mapply_2.h:46