Skip to content

Commit 67cf65c

Browse files
committed
replace std::(unary|binary)_function with std::function if >= C++11
1 parent 9f29fd2 commit 67cf65c

File tree

2 files changed

+58
-48
lines changed

2 files changed

+58
-48
lines changed

inst/include/Rcpp/Language.h

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
//
1+
32
// Language.h: Rcpp R/C++ interface class library -- language objects (calls)
43
//
5-
// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
4+
// Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
65
//
76
// This file is part of Rcpp.
87
//
@@ -35,8 +34,8 @@ namespace Rcpp{
3534
{
3635
public:
3736

38-
typedef typename DottedPairProxyPolicy<Language_Impl>::DottedPairProxy Proxy ;
39-
typedef typename DottedPairProxyPolicy<Language_Impl>::const_DottedPairProxy const_Proxy ;
37+
typedef typename DottedPairProxyPolicy<Language_Impl>::DottedPairProxy Proxy;
38+
typedef typename DottedPairProxyPolicy<Language_Impl>::const_DottedPairProxy const_Proxy;
4039

4140
RCPP_GENERATE_CTOR_ASSIGN(Language_Impl)
4241

@@ -49,7 +48,7 @@ namespace Rcpp{
4948
* to a call using as.call
5049
*/
5150
Language_Impl(SEXP x){
52-
Storage::set__( r_cast<LANGSXP>(x) ) ;
51+
Storage::set__( r_cast<LANGSXP>(x) );
5352
}
5453

5554
/**
@@ -62,7 +61,7 @@ namespace Rcpp{
6261
* > call( "rnorm" )
6362
*/
6463
explicit Language_Impl( const std::string& symbol ){
65-
Storage::set__( Rf_lang1( Rf_install(symbol.c_str()) ) ) ;
64+
Storage::set__( Rf_lang1( Rf_install(symbol.c_str()) ) );
6665
}
6766

6867
/**
@@ -74,7 +73,7 @@ namespace Rcpp{
7473
* > call( "rnorm" )
7574
*/
7675
explicit Language_Impl( const Symbol& symbol ){
77-
Storage::set__( Rf_lang1( symbol ) ) ;
76+
Storage::set__( Rf_lang1( symbol ) );
7877
}
7978

8079
/**
@@ -83,7 +82,7 @@ namespace Rcpp{
8382
* @param function function to call
8483
*/
8584
explicit Language_Impl( const Function& function) {
86-
Storage::set__( Rf_lang1( function ) ) ;
85+
Storage::set__( Rf_lang1( function ) );
8786
}
8887

8988
/**
@@ -109,23 +108,23 @@ namespace Rcpp{
109108
* sets the symbol of the call
110109
*/
111110
void setSymbol( const std::string& symbol){
112-
setSymbol( Symbol( symbol ) ) ;
111+
setSymbol( Symbol( symbol ) );
113112
}
114113

115114
/**
116115
* sets the symbol of the call
117116
*/
118117
void setSymbol( const Symbol& symbol ){
119-
SEXP x = Storage::get__() ;
120-
SETCAR( x, symbol ) ;
118+
SEXP x = Storage::get__();
119+
SETCAR( x, symbol );
121120
SET_TAG(x, R_NilValue);
122121
}
123122

124123
/**
125124
* sets the function
126125
*/
127126
void setFunction( const Function& function){
128-
SEXP x = Storage::get__() ;
127+
SEXP x = Storage::get__();
129128
SETCAR( x, function );
130129
SET_TAG(x, R_NilValue); /* probably not necessary */
131130
}
@@ -134,83 +133,91 @@ namespace Rcpp{
134133
* eval this call in the global environment
135134
*/
136135
SEXP eval() const {
137-
return Rcpp_fast_eval( Storage::get__(), R_GlobalEnv ) ;
136+
return Rcpp_fast_eval( Storage::get__(), R_GlobalEnv );
138137
}
139138

140139
/**
141140
* eval this call in the requested environment
142141
*/
143142
SEXP eval(SEXP env) const {
144-
return Rcpp_fast_eval( Storage::get__(), env ) ;
143+
return Rcpp_fast_eval( Storage::get__(), env );
145144
}
146145

147146
SEXP fast_eval() const {
148-
return internal::Rcpp_eval_impl( Storage::get__(), R_GlobalEnv) ;
147+
return internal::Rcpp_eval_impl( Storage::get__(), R_GlobalEnv);
149148
}
150149
SEXP fast_eval(SEXP env ) const {
151-
return internal::Rcpp_eval_impl( Storage::get__(), env) ;
150+
return internal::Rcpp_eval_impl( Storage::get__(), env);
152151
}
153152

154153
void update( SEXP x){
155-
SET_TYPEOF( x, LANGSXP ) ;
156-
SET_TAG( x, R_NilValue ) ;
154+
SET_TYPEOF( x, LANGSXP );
155+
SET_TAG( x, R_NilValue );
157156
}
158157

159158
};
160159

161-
typedef Language_Impl<PreserveStorage> Language ;
160+
typedef Language_Impl<PreserveStorage> Language;
162161

163162
template <typename RESULT_TYPE=SEXP>
164163
class fixed_call {
165164
public:
166-
typedef RESULT_TYPE result_type ;
165+
typedef RESULT_TYPE result_type;
167166

168167
fixed_call( Language call_ ) : call(call_){}
169168
fixed_call( Function fun ) : call(fun){}
170169

171170
RESULT_TYPE operator()(){
172-
return as<RESULT_TYPE>( call.eval() ) ;
171+
return as<RESULT_TYPE>( call.eval() );
173172
}
174173

175174
private:
176-
Language call ;
177-
} ;
175+
Language call;
176+
};
178177

179178
template <typename T, typename RESULT_TYPE = SEXP>
180-
class unary_call : public std::unary_function<T,RESULT_TYPE> {
179+
#if __cplusplus < 201103L
180+
class unary_call : public std::unary_function<T,RESULT_TYPE> {
181+
#else
182+
class unary_call : public std::function<RESULT_TYPE(T)> {
183+
#endif
181184
public:
182185
unary_call( Language call_ ) : call(call_), proxy(call_,1) {}
183186
unary_call( Language call_, R_xlen_t index ) : call(call_), proxy(call_,index){}
184187
unary_call( Function fun ) : call( fun, R_NilValue), proxy(call,1) {}
185188

186189
RESULT_TYPE operator()( const T& object ){
187-
proxy = object ;
188-
return as<RESULT_TYPE>( call.eval() ) ;
190+
proxy = object;
191+
return as<RESULT_TYPE>( call.eval() );
189192
}
190193

191194
private:
192-
Language call ;
193-
Language::Proxy proxy ;
194-
} ;
195+
Language call;
196+
Language::Proxy proxy;
197+
};
195198

196199
template <typename T1, typename T2, typename RESULT_TYPE = SEXP>
200+
#if __cplusplus < 201103L
197201
class binary_call : public std::binary_function<T1,T2,RESULT_TYPE> {
202+
#else
203+
class binary_call : public std::function<RESULT_TYPE(T1,T2)> {
204+
#endif
198205
public:
199206
binary_call( Language call_ ) : call(call_), proxy1(call_,1), proxy2(call_,2) {}
200207
binary_call( Language call_, R_xlen_t index1, R_xlen_t index2 ) : call(call_), proxy1(call_,index1), proxy2(call_,index2){}
201208
binary_call( Function fun) : call(fun, R_NilValue, R_NilValue), proxy1(call,1), proxy2(call,2){}
202209

203210
RESULT_TYPE operator()( const T1& o1, const T2& o2 ){
204-
proxy1 = o1 ;
205-
proxy2 = o2 ;
206-
return as<RESULT_TYPE>( call.eval() ) ;
211+
proxy1 = o1;
212+
proxy2 = o2;
213+
return as<RESULT_TYPE>( call.eval() );
207214
}
208215

209216
private:
210-
Language call ;
211-
Language::Proxy proxy1 ;
212-
Language::Proxy proxy2 ;
213-
} ;
217+
Language call;
218+
Language::Proxy proxy1;
219+
Language::Proxy proxy2;
220+
};
214221

215222
} // namespace Rcpp
216223

inst/include/Rcpp/StringTransformer.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2-
//
1+
32
// clone.h: Rcpp R/C++ interface class library -- clone RObject's
43
//
5-
// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
4+
// Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
65
//
76
// This file is part of Rcpp.
87
//
@@ -27,25 +26,29 @@
2726
namespace Rcpp{
2827

2928
template <typename UnaryOperator>
30-
class StringTransformer : public std::unary_function<const char*, const char*>{
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
3134
public:
3235
StringTransformer( const UnaryOperator& op_ ): op(op_), buffer(){}
3336
~StringTransformer(){}
3437

3538
const char* operator()(const char* input ) {
36-
buffer = input ;
37-
std::transform( buffer.begin(), buffer.end(), buffer.begin(), op ) ;
38-
return buffer.c_str() ;
39+
buffer = input;
40+
std::transform( buffer.begin(), buffer.end(), buffer.begin(), op );
41+
return buffer.c_str();
3942
}
4043

4144
private:
42-
const UnaryOperator& op ;
43-
std::string buffer ;
44-
} ;
45+
const UnaryOperator& op;
46+
std::string buffer;
47+
};
4548

4649
template <typename UnaryOperator>
4750
StringTransformer<UnaryOperator> make_string_transformer( const UnaryOperator& fun){
48-
return StringTransformer<UnaryOperator>( fun ) ;
51+
return StringTransformer<UnaryOperator>( fun );
4952
}
5053

5154
}

0 commit comments

Comments
 (0)