Rcpp Version 1.0.14
Loading...
Searching...
No Matches
StringTransformer.h
Go to the documentation of this file.
1
2// clone.h: Rcpp R/C++ interface class library -- clone RObject's
3//
4// Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
5//
6// This file is part of Rcpp.
7//
8// Rcpp is free software: you can redistribute it and/or modify it
9// under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 2 of the License, or
11// (at your option) any later version.
12//
13// Rcpp is distributed in the hope that it will be useful, but
14// WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
20
21#ifndef Rcpp__StringTransformer_h
22#define Rcpp__StringTransformer_h
23
24#include <RcppCommon.h>
25
26namespace Rcpp{
27
28 template <typename UnaryOperator>
29#if __cplusplus < 201103L
30 class StringTransformer : public std::unary_function<const char*, const char*> {
31#else
32 class StringTransformer : public std::function<const char*(const char*)> {
33#endif
34 public:
37
38 const char* operator()(const char* input ) {
39 buffer = input;
40 std::transform( buffer.begin(), buffer.end(), buffer.begin(), op );
41 return buffer.c_str();
42 }
43
44 private:
46 std::string buffer;
47 };
48
49 template <typename UnaryOperator>
53
54}
55
56#endif
StringTransformer(const UnaryOperator &op_)
const char * operator()(const char *input)
const UnaryOperator & op
Rcpp API.
Definition algo.h:28
StringTransformer< UnaryOperator > make_string_transformer(const UnaryOperator &fun)
T as(SEXP x)
Definition as.h:151