Skip to content

Commit

Permalink
Merge pull request #1202 from RcppCore/bugfix/unary_binary_func_depre…
Browse files Browse the repository at this point in the history
…cation

Remove deprecated std::(unary|binary)_function (closes #1201)
  • Loading branch information
eddelbuettel authored Mar 12, 2022
2 parents 9f29fd2 + beb0150 commit f12d9fd
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 96 deletions.
17 changes: 17 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
2022-03-10 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll minor version
* inst/include/Rcpp/config.h: Idem

* inst/tinytest/cpp/sugar.cpp: Also conditionally replace
std::unary_function with std::function
* vignettes/rmd/Rcpp-sugar.Rmd: Replace std::unary_function example
with std::function (implicitly requiring C++ in vignette example)
* vignettes/rmd/Rcpp-FAQ.Rmd: Idem

2022-03-09 Dirk Eddelbuettel <edd@debian.org>

* inst/include/Rcpp/Language.h: To quieten compilations, replace
std::(unary|binary)_function with std::function for C++11 or later
* inst/include/Rcpp/StringTransformer.he: Idem

2022-01-21 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll minor version
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Rcpp
Title: Seamless R and C++ Integration
Version: 1.0.8.1
Date: 2022-01-21
Version: 1.0.8.2
Date: 2022-03-10
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,
Nathan Russell, Inaki Ucar, Douglas Bates and John Chambers
Maintainer: Dirk Eddelbuettel <edd@debian.org>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![BioConductor use](https://jangorecki.gitlab.io/rdeps/Rcpp/BioC_usage.svg?sanitize=true)](https://cran.r-project.org/package=Rcpp)
[![StackOverflow](https://img.shields.io/badge/stackoverflow-rcpp-orange.svg)](https://stackoverflow.com/questions/tagged/rcpp)
[![JSS](https://img.shields.io/badge/JSS-10.18637%2Fjss.v040.i08-brightgreen)](https://dx.doi.org/10.18637/jss.v040.i08)
[![Springer useR!](https://img.shields.io/badge/Springer%20useR!-10.1007%2F978--1--4614--6868--4-brightgreen)](https://www.springer.com/gp/book/9781461468677)
[![Springer useR!](https://img.shields.io/badge/Springer%20useR!-10.1007%2F978--1--4614--6868--4-brightgreen)](https://link.springer.com/gp/book/9781461468677)
[![TAS](https://img.shields.io/badge/TAS-10.1080%2F00031305.2017.1375990-brightgreen)](https://dx.doi.org/10.1080/00031305.2017.1375990)

### Synopsis
Expand Down
23 changes: 23 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
\newcommand{\ghpr}{\href{https://github.com/RcppCore/Rcpp/pull/#1}{##1}}
\newcommand{\ghit}{\href{https://github.com/RcppCore/Rcpp/issues/#1}{##1}}

\section{Changes in Rcpp hotfix release version 1.0.8.2 (2022-03-10)}{
\itemize{
\item Changes in Rcpp API:
\itemize{
\item Accomodate C++98 compilation by adjusting attributes.cpp (Dirk in
\ghpr{1193} fixing \ghit{1192})
\item Accomodate newest compilers replacing deprecated
\code{std::unary_function} and \code{std::binary_function} with
\code{std::function} (Dirk in \ghpr{1202} fixing \ghit{1201} and
CRAN request)
}
\item Changes in Rcpp Documentation:
\itemize{
\item Adjust one overflowing column (Bill Denney in \ghpr{1196} fixing
\ghit{1195})
}
\item Changes in Rcpp Deployment:
\itemize{
\item Accomodate four digit version numbers in unit test (Dirk)
}
}
}

\section{Changes in Rcpp release version 1.0.8 (2022-01-11)}{
\itemize{
\item Changes in Rcpp API:
Expand Down
81 changes: 44 additions & 37 deletions inst/include/Rcpp/Language.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//

// Language.h: Rcpp R/C++ interface class library -- language objects (calls)
//
// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Expand Down Expand Up @@ -35,8 +34,8 @@ namespace Rcpp{
{
public:

typedef typename DottedPairProxyPolicy<Language_Impl>::DottedPairProxy Proxy ;
typedef typename DottedPairProxyPolicy<Language_Impl>::const_DottedPairProxy const_Proxy ;
typedef typename DottedPairProxyPolicy<Language_Impl>::DottedPairProxy Proxy;
typedef typename DottedPairProxyPolicy<Language_Impl>::const_DottedPairProxy const_Proxy;

RCPP_GENERATE_CTOR_ASSIGN(Language_Impl)

Expand All @@ -49,7 +48,7 @@ namespace Rcpp{
* to a call using as.call
*/
Language_Impl(SEXP x){
Storage::set__( r_cast<LANGSXP>(x) ) ;
Storage::set__( r_cast<LANGSXP>(x) );
}

/**
Expand All @@ -62,7 +61,7 @@ namespace Rcpp{
* > call( "rnorm" )
*/
explicit Language_Impl( const std::string& symbol ){
Storage::set__( Rf_lang1( Rf_install(symbol.c_str()) ) ) ;
Storage::set__( Rf_lang1( Rf_install(symbol.c_str()) ) );
}

/**
Expand All @@ -74,7 +73,7 @@ namespace Rcpp{
* > call( "rnorm" )
*/
explicit Language_Impl( const Symbol& symbol ){
Storage::set__( Rf_lang1( symbol ) ) ;
Storage::set__( Rf_lang1( symbol ) );
}

/**
Expand All @@ -83,7 +82,7 @@ namespace Rcpp{
* @param function function to call
*/
explicit Language_Impl( const Function& function) {
Storage::set__( Rf_lang1( function ) ) ;
Storage::set__( Rf_lang1( function ) );
}

/**
Expand All @@ -109,23 +108,23 @@ namespace Rcpp{
* sets the symbol of the call
*/
void setSymbol( const std::string& symbol){
setSymbol( Symbol( symbol ) ) ;
setSymbol( Symbol( symbol ) );
}

/**
* sets the symbol of the call
*/
void setSymbol( const Symbol& symbol ){
SEXP x = Storage::get__() ;
SETCAR( x, symbol ) ;
SEXP x = Storage::get__();
SETCAR( x, symbol );
SET_TAG(x, R_NilValue);
}

/**
* sets the function
*/
void setFunction( const Function& function){
SEXP x = Storage::get__() ;
SEXP x = Storage::get__();
SETCAR( x, function );
SET_TAG(x, R_NilValue); /* probably not necessary */
}
Expand All @@ -134,83 +133,91 @@ namespace Rcpp{
* eval this call in the global environment
*/
SEXP eval() const {
return Rcpp_fast_eval( Storage::get__(), R_GlobalEnv ) ;
return Rcpp_fast_eval( Storage::get__(), R_GlobalEnv );
}

/**
* eval this call in the requested environment
*/
SEXP eval(SEXP env) const {
return Rcpp_fast_eval( Storage::get__(), env ) ;
return Rcpp_fast_eval( Storage::get__(), env );
}

SEXP fast_eval() const {
return internal::Rcpp_eval_impl( Storage::get__(), R_GlobalEnv) ;
return internal::Rcpp_eval_impl( Storage::get__(), R_GlobalEnv);
}
SEXP fast_eval(SEXP env ) const {
return internal::Rcpp_eval_impl( Storage::get__(), env) ;
return internal::Rcpp_eval_impl( Storage::get__(), env);
}

void update( SEXP x){
SET_TYPEOF( x, LANGSXP ) ;
SET_TAG( x, R_NilValue ) ;
SET_TYPEOF( x, LANGSXP );
SET_TAG( x, R_NilValue );
}

};

typedef Language_Impl<PreserveStorage> Language ;
typedef Language_Impl<PreserveStorage> Language;

template <typename RESULT_TYPE=SEXP>
class fixed_call {
public:
typedef RESULT_TYPE result_type ;
typedef RESULT_TYPE result_type;

fixed_call( Language call_ ) : call(call_){}
fixed_call( Function fun ) : call(fun){}

RESULT_TYPE operator()(){
return as<RESULT_TYPE>( call.eval() ) ;
return as<RESULT_TYPE>( call.eval() );
}

private:
Language call ;
} ;
Language call;
};

template <typename T, typename RESULT_TYPE = SEXP>
class unary_call : public std::unary_function<T,RESULT_TYPE> {
#if __cplusplus < 201103L
class unary_call : public std::unary_function<T,RESULT_TYPE> {
#else
class unary_call : public std::function<RESULT_TYPE(T)> {
#endif
public:
unary_call( Language call_ ) : call(call_), proxy(call_,1) {}
unary_call( Language call_, R_xlen_t index ) : call(call_), proxy(call_,index){}
unary_call( Function fun ) : call( fun, R_NilValue), proxy(call,1) {}

RESULT_TYPE operator()( const T& object ){
proxy = object ;
return as<RESULT_TYPE>( call.eval() ) ;
proxy = object;
return as<RESULT_TYPE>( call.eval() );
}

private:
Language call ;
Language::Proxy proxy ;
} ;
Language call;
Language::Proxy proxy;
};

template <typename T1, typename T2, typename RESULT_TYPE = SEXP>
#if __cplusplus < 201103L
class binary_call : public std::binary_function<T1,T2,RESULT_TYPE> {
#else
class binary_call : public std::function<RESULT_TYPE(T1,T2)> {
#endif
public:
binary_call( Language call_ ) : call(call_), proxy1(call_,1), proxy2(call_,2) {}
binary_call( Language call_, R_xlen_t index1, R_xlen_t index2 ) : call(call_), proxy1(call_,index1), proxy2(call_,index2){}
binary_call( Function fun) : call(fun, R_NilValue, R_NilValue), proxy1(call,1), proxy2(call,2){}

RESULT_TYPE operator()( const T1& o1, const T2& o2 ){
proxy1 = o1 ;
proxy2 = o2 ;
return as<RESULT_TYPE>( call.eval() ) ;
proxy1 = o1;
proxy2 = o2;
return as<RESULT_TYPE>( call.eval() );
}

private:
Language call ;
Language::Proxy proxy1 ;
Language::Proxy proxy2 ;
} ;
Language call;
Language::Proxy proxy1;
Language::Proxy proxy2;
};

} // namespace Rcpp

Expand Down
25 changes: 14 additions & 11 deletions inst/include/Rcpp/StringTransformer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
//

// clone.h: Rcpp R/C++ interface class library -- clone RObject's
//
// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Expand All @@ -27,25 +26,29 @@
namespace Rcpp{

template <typename UnaryOperator>
class StringTransformer : public std::unary_function<const char*, const char*>{
#if __cplusplus < 201103L
class StringTransformer : public std::unary_function<const char*, const char*> {
#else
class StringTransformer : public std::function<const char*(const char*)> {
#endif
public:
StringTransformer( const UnaryOperator& op_ ): op(op_), buffer(){}
~StringTransformer(){}

const char* operator()(const char* input ) {
buffer = input ;
std::transform( buffer.begin(), buffer.end(), buffer.begin(), op ) ;
return buffer.c_str() ;
buffer = input;
std::transform( buffer.begin(), buffer.end(), buffer.begin(), op );
return buffer.c_str();
}

private:
const UnaryOperator& op ;
std::string buffer ;
} ;
const UnaryOperator& op;
std::string buffer;
};

template <typename UnaryOperator>
StringTransformer<UnaryOperator> make_string_transformer( const UnaryOperator& fun){
return StringTransformer<UnaryOperator>( fun ) ;
return StringTransformer<UnaryOperator>( fun );
}

}
Expand Down
4 changes: 2 additions & 2 deletions inst/include/Rcpp/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define RCPP_VERSION_STRING "1.0.8"

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

#endif
10 changes: 7 additions & 3 deletions inst/tinytest/cpp/sugar.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
//

// sugar.cpp: Rcpp R/C++ interface class library -- sugar unit tests
//
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2012 - 2022 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Expand All @@ -23,7 +22,12 @@
using namespace Rcpp ;

template <typename T>

#if __cplusplus < 201103L
class square : public std::unary_function<T,T> {
#else
class square : public std::function<T(T)> {
#endif
public:
T operator()( T t) const { return t*t ; }
} ;
Expand Down
Binary file modified vignettes/pdf/Rcpp-FAQ.pdf
Binary file not shown.
Binary file modified vignettes/pdf/Rcpp-sugar.pdf
Binary file not shown.
5 changes: 3 additions & 2 deletions vignettes/rmd/Rcpp-FAQ.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,14 @@ what we show below.


### Using inline with Templated Code

Most certainly, consider this simple example of a templated class
which squares its argument:

```{r}
inc <- 'template <typename T>
class square :
public std::unary_function<T,T> {
public std::function<T(T)> {
public:
T operator()( T t) const {
return t*t;
Expand Down Expand Up @@ -684,7 +685,7 @@ will even run the R part at the end.
#include <Rcpp.h>

template <typename T> class square :
public std::unary_function<T,T> {
public std::function<T(T)> {
public:
T operator()( T t) const {
return t*t ;
Expand Down
Loading

0 comments on commit f12d9fd

Please sign in to comment.