Rcpp Version 1.1.2
Loading...
Searching...
No Matches
lapply.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// lapply.h: Rcpp R/C++ interface class library -- lapply
4//
5// Copyright (C) 2010 - 2024 Dirk Eddelbuettel and Romain Francois
6// Copyright (C) 2025 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__lapply_h
24#define Rcpp__sugar__lapply_h
25
26namespace Rcpp{
27namespace sugar{
28
29template <int RTYPE, bool NA, typename T, typename Function>
30class Lapply : public VectorBase<
31 VECSXP ,
32 true ,
33 Lapply<RTYPE,NA,T,Function>
34> {
35public:
37 typedef typename ::Rcpp::traits::result_of<Function, T>::type result_type ;
38
39 Lapply( const VEC& vec_, Function fun_ ) :
40 vec(vec_), fun(fun_){}
41
42 inline SEXP operator[]( R_xlen_t i ) const {
43 return Rcpp::wrap( fun( vec[i] ) );
44 }
45 inline R_xlen_t size() const { return vec.size() ; }
46
47private:
48 const VEC& vec ;
50} ;
51
52} // sugar
53
54template <int RTYPE, bool NA, typename T, typename Function >
59
60} // Rcpp
61
62#endif
Lapply(const VEC &vec_, Function fun_)
Definition lapply.h:39
const VEC & vec
Definition lapply.h:48
SEXP operator[](R_xlen_t i) const
Definition lapply.h:42
R_xlen_t size() const
Definition lapply.h:45
::Rcpp::traits::result_of< Function, T >::type result_type
Definition lapply.h:37
Rcpp::VectorBase< RTYPE, NA, T > VEC
Definition lapply.h:36
Rcpp API.
Definition algo.h:28
Function_Impl< PreserveStorage > Function
Definition Function.h:144
sugar::Lapply< RTYPE, NA, T, Function > lapply(const Rcpp::VectorBase< RTYPE, NA, T > &t, Function fun)
Definition lapply.h:56
SEXP wrap(const Date &date)
Definition Date.h:38