Skip to content

Commit f12d9fd

Browse files
authored
Merge pull request #1202 from RcppCore/bugfix/unary_binary_func_deprecation
Remove deprecated std::(unary|binary)_function (closes #1201)
2 parents 9f29fd2 + beb0150 commit f12d9fd

File tree

12 files changed

+151
-96
lines changed

12 files changed

+151
-96
lines changed

ChangeLog

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2022-03-10 Dirk Eddelbuettel <[email protected]>
2+
3+
* DESCRIPTION (Version, Date): Roll minor version
4+
* inst/include/Rcpp/config.h: Idem
5+
6+
* inst/tinytest/cpp/sugar.cpp: Also conditionally replace
7+
std::unary_function with std::function
8+
* vignettes/rmd/Rcpp-sugar.Rmd: Replace std::unary_function example
9+
with std::function (implicitly requiring C++ in vignette example)
10+
* vignettes/rmd/Rcpp-FAQ.Rmd: Idem
11+
12+
2022-03-09 Dirk Eddelbuettel <[email protected]>
13+
14+
* inst/include/Rcpp/Language.h: To quieten compilations, replace
15+
std::(unary|binary)_function with std::function for C++11 or later
16+
* inst/include/Rcpp/StringTransformer.he: Idem
17+
118
2022-01-21 Dirk Eddelbuettel <[email protected]>
219

320
* DESCRIPTION (Version, Date): Roll minor version

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 1.0.8.1
4-
Date: 2022-01-21
3+
Version: 1.0.8.2
4+
Date: 2022-03-10
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,
66
Nathan Russell, Inaki Ucar, Douglas Bates and John Chambers
77
Maintainer: Dirk Eddelbuettel <[email protected]>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[![BioConductor use](https://jangorecki.gitlab.io/rdeps/Rcpp/BioC_usage.svg?sanitize=true)](https://cran.r-project.org/package=Rcpp)
1515
[![StackOverflow](https://img.shields.io/badge/stackoverflow-rcpp-orange.svg)](https://stackoverflow.com/questions/tagged/rcpp)
1616
[![JSS](https://img.shields.io/badge/JSS-10.18637%2Fjss.v040.i08-brightgreen)](https://dx.doi.org/10.18637/jss.v040.i08)
17-
[![Springer useR!](https://img.shields.io/badge/Springer%20useR!-10.1007%2F978--1--4614--6868--4-brightgreen)](https://www.springer.com/gp/book/9781461468677)
17+
[![Springer useR!](https://img.shields.io/badge/Springer%20useR!-10.1007%2F978--1--4614--6868--4-brightgreen)](https://link.springer.com/gp/book/9781461468677)
1818
[![TAS](https://img.shields.io/badge/TAS-10.1080%2F00031305.2017.1375990-brightgreen)](https://dx.doi.org/10.1080/00031305.2017.1375990)
1919

2020
### Synopsis

inst/NEWS.Rd

+23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33
\newcommand{\ghpr}{\href{https://github.com/RcppCore/Rcpp/pull/#1}{##1}}
44
\newcommand{\ghit}{\href{https://github.com/RcppCore/Rcpp/issues/#1}{##1}}
55

6+
\section{Changes in Rcpp hotfix release version 1.0.8.2 (2022-03-10)}{
7+
\itemize{
8+
\item Changes in Rcpp API:
9+
\itemize{
10+
\item Accomodate C++98 compilation by adjusting attributes.cpp (Dirk in
11+
\ghpr{1193} fixing \ghit{1192})
12+
\item Accomodate newest compilers replacing deprecated
13+
\code{std::unary_function} and \code{std::binary_function} with
14+
\code{std::function} (Dirk in \ghpr{1202} fixing \ghit{1201} and
15+
CRAN request)
16+
}
17+
\item Changes in Rcpp Documentation:
18+
\itemize{
19+
\item Adjust one overflowing column (Bill Denney in \ghpr{1196} fixing
20+
\ghit{1195})
21+
}
22+
\item Changes in Rcpp Deployment:
23+
\itemize{
24+
\item Accomodate four digit version numbers in unit test (Dirk)
25+
}
26+
}
27+
}
28+
629
\section{Changes in Rcpp release version 1.0.8 (2022-01-11)}{
730
\itemize{
831
\item Changes in Rcpp API:

inst/include/Rcpp/Language.h

+44-37
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

+14-11
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
}

inst/include/Rcpp/config.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define RCPP_VERSION_STRING "1.0.8"
3131

3232
// the current source snapshot (using four components, if a fifth is used in DESCRIPTION we ignore it)
33-
#define RCPP_DEV_VERSION RcppDevVersion(1,0,8,1)
34-
#define RCPP_DEV_VERSION_STRING "1.0.8.1"
33+
#define RCPP_DEV_VERSION RcppDevVersion(1,0,8,2)
34+
#define RCPP_DEV_VERSION_STRING "1.0.8.2"
3535

3636
#endif

inst/tinytest/cpp/sugar.cpp

+7-3
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
// sugar.cpp: Rcpp R/C++ interface class library -- sugar unit tests
43
//
5-
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
4+
// Copyright (C) 2012 - 2022 Dirk Eddelbuettel and Romain Francois
65
//
76
// This file is part of Rcpp.
87
//
@@ -23,7 +22,12 @@
2322
using namespace Rcpp ;
2423

2524
template <typename T>
25+
26+
#if __cplusplus < 201103L
2627
class square : public std::unary_function<T,T> {
28+
#else
29+
class square : public std::function<T(T)> {
30+
#endif
2731
public:
2832
T operator()( T t) const { return t*t ; }
2933
} ;

vignettes/pdf/Rcpp-FAQ.pdf

5.2 KB
Binary file not shown.

vignettes/pdf/Rcpp-sugar.pdf

4.47 KB
Binary file not shown.

vignettes/rmd/Rcpp-FAQ.Rmd

+3-2
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,14 @@ what we show below.
642642

643643

644644
### Using inline with Templated Code
645+
645646
Most certainly, consider this simple example of a templated class
646647
which squares its argument:
647648

648649
```{r}
649650
inc <- 'template <typename T>
650651
class square :
651-
public std::unary_function<T,T> {
652+
public std::function<T(T)> {
652653
public:
653654
T operator()( T t) const {
654655
return t*t;
@@ -684,7 +685,7 @@ will even run the R part at the end.
684685
#include <Rcpp.h>
685686

686687
template <typename T> class square :
687-
public std::unary_function<T,T> {
688+
public std::function<T(T)> {
688689
public:
689690
T operator()( T t) const {
690691
return t*t ;

0 commit comments

Comments
 (0)