diff --git a/ChangeLog b/ChangeLog index dffaa3964..1218548e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2022-03-10 Dirk Eddelbuettel + + * 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 + + * 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 * DESCRIPTION (Version, Date): Roll minor version diff --git a/DESCRIPTION b/DESCRIPTION index 250dacb88..26a90154c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 diff --git a/README.md b/README.md index bf214182d..3bd71d4f7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index fa4c787d0..e5e6389da 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -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: diff --git a/inst/include/Rcpp/Language.h b/inst/include/Rcpp/Language.h index 202fe8b21..03983f5e5 100644 --- a/inst/include/Rcpp/Language.h +++ b/inst/include/Rcpp/Language.h @@ -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. // @@ -35,8 +34,8 @@ namespace Rcpp{ { public: - typedef typename DottedPairProxyPolicy::DottedPairProxy Proxy ; - typedef typename DottedPairProxyPolicy::const_DottedPairProxy const_Proxy ; + typedef typename DottedPairProxyPolicy::DottedPairProxy Proxy; + typedef typename DottedPairProxyPolicy::const_DottedPairProxy const_Proxy; RCPP_GENERATE_CTOR_ASSIGN(Language_Impl) @@ -49,7 +48,7 @@ namespace Rcpp{ * to a call using as.call */ Language_Impl(SEXP x){ - Storage::set__( r_cast(x) ) ; + Storage::set__( r_cast(x) ); } /** @@ -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()) ) ); } /** @@ -74,7 +73,7 @@ namespace Rcpp{ * > call( "rnorm" ) */ explicit Language_Impl( const Symbol& symbol ){ - Storage::set__( Rf_lang1( symbol ) ) ; + Storage::set__( Rf_lang1( symbol ) ); } /** @@ -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 ) ); } /** @@ -109,15 +108,15 @@ 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); } @@ -125,7 +124,7 @@ namespace Rcpp{ * 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 */ } @@ -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 Language ; + typedef Language_Impl Language; template 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( call.eval() ) ; + return as( call.eval() ); } private: - Language call ; - } ; + Language call; + }; template - class unary_call : public std::unary_function { +#if __cplusplus < 201103L + class unary_call : public std::unary_function { +#else + class unary_call : public std::function { +#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( call.eval() ) ; + proxy = object; + return as( call.eval() ); } private: - Language call ; - Language::Proxy proxy ; - } ; + Language call; + Language::Proxy proxy; + }; template +#if __cplusplus < 201103L class binary_call : public std::binary_function { +#else + class binary_call : public std::function { +#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( call.eval() ) ; + proxy1 = o1; + proxy2 = o2; + return as( call.eval() ); } private: - Language call ; - Language::Proxy proxy1 ; - Language::Proxy proxy2 ; - } ; + Language call; + Language::Proxy proxy1; + Language::Proxy proxy2; + }; } // namespace Rcpp diff --git a/inst/include/Rcpp/StringTransformer.h b/inst/include/Rcpp/StringTransformer.h index 94ebe7fed..0824c031c 100644 --- a/inst/include/Rcpp/StringTransformer.h +++ b/inst/include/Rcpp/StringTransformer.h @@ -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. // @@ -27,25 +26,29 @@ namespace Rcpp{ template - class StringTransformer : public std::unary_function{ +#if __cplusplus < 201103L + class StringTransformer : public std::unary_function { +#else + class StringTransformer : public std::function { +#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 StringTransformer make_string_transformer( const UnaryOperator& fun){ - return StringTransformer( fun ) ; + return StringTransformer( fun ); } } diff --git a/inst/include/Rcpp/config.h b/inst/include/Rcpp/config.h index 4b6c5ffb4..8b7992d5b 100644 --- a/inst/include/Rcpp/config.h +++ b/inst/include/Rcpp/config.h @@ -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 diff --git a/inst/tinytest/cpp/sugar.cpp b/inst/tinytest/cpp/sugar.cpp index 6829638a8..3d17bd9e4 100644 --- a/inst/tinytest/cpp/sugar.cpp +++ b/inst/tinytest/cpp/sugar.cpp @@ -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. // @@ -23,7 +22,12 @@ using namespace Rcpp ; template + +#if __cplusplus < 201103L class square : public std::unary_function { +#else +class square : public std::function { +#endif public: T operator()( T t) const { return t*t ; } } ; diff --git a/vignettes/pdf/Rcpp-FAQ.pdf b/vignettes/pdf/Rcpp-FAQ.pdf index 604ce5310..cdc1e492a 100644 Binary files a/vignettes/pdf/Rcpp-FAQ.pdf and b/vignettes/pdf/Rcpp-FAQ.pdf differ diff --git a/vignettes/pdf/Rcpp-sugar.pdf b/vignettes/pdf/Rcpp-sugar.pdf index 7e6d51655..42ee22aea 100644 Binary files a/vignettes/pdf/Rcpp-sugar.pdf and b/vignettes/pdf/Rcpp-sugar.pdf differ diff --git a/vignettes/rmd/Rcpp-FAQ.Rmd b/vignettes/rmd/Rcpp-FAQ.Rmd index 37d76793d..1295988e0 100644 --- a/vignettes/rmd/Rcpp-FAQ.Rmd +++ b/vignettes/rmd/Rcpp-FAQ.Rmd @@ -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 class square : - public std::unary_function { + public std::function { public: T operator()( T t) const { return t*t; @@ -684,7 +685,7 @@ will even run the R part at the end. #include template class square : - public std::unary_function { + public std::function { public: T operator()( T t) const { return t*t ; diff --git a/vignettes/rmd/Rcpp-sugar.Rmd b/vignettes/rmd/Rcpp-sugar.Rmd index b396e8355..ff7068507 100644 --- a/vignettes/rmd/Rcpp-sugar.Rmd +++ b/vignettes/rmd/Rcpp-sugar.Rmd @@ -137,7 +137,7 @@ high-level \proglang{R} syntax in \proglang{C++}. Hence, with \sugar, the \proglang{C++} version of `foo` now becomes: ```cpp -Rcpp::NumericVector foo(Rcpp::NumericVector x, +Rcpp::NumericVector foo(Rcpp::NumericVector x, Rcpp::NumericVector y) { return ifelse(x < y, x * x, -(y * y)); } @@ -308,7 +308,7 @@ length. Each element of the result expression evaluates to `TRUE` if the corresponding input is a missing value, or `FALSE` otherwise. ```cpp -IntegerVector x = +IntegerVector x = IntegerVector::create(0, 1, NA_INTEGER, 3); is_na(x) @@ -322,7 +322,7 @@ Given a sugar expression of any type, `seq_along` creates an integer sugar expression whose values go from 1 to the size of the input. ```cpp -IntegerVector x = +IntegerVector x = IntegerVector::create( 0, 1, NA_INTEGER, 3 ); IntegerVector y = seq_along(x); @@ -337,7 +337,7 @@ second expression, since the abstract syntax tree is built at compile time. ### seq_len -`seq_len` creates an integer sugar expression whose +`seq_len` creates an integer sugar expression whose \ith\ element expands to `i`. `seq_len` is particularly useful in conjunction with `sapply` and `lapply`. @@ -411,7 +411,7 @@ called `result_type` ```cpp template -struct square : std::unary_function { +struct square : std::function { T operator()(const T& x){ return x * x; } @@ -491,9 +491,9 @@ beta, binom, cauchy, chisq, exp, f, gamma, geom, hyper, lnorm, logis, nbeta, nbinom, nbinom_mu, nchisq, nf, norm, nt, pois, t, unif, and weibull. Note that the parameterization used in these sugar functions may differ between -the top-level functions exposed in an \proglang{R} session. For example, +the top-level functions exposed in an \proglang{R} session. For example, the internal \code{rexp} is parameterized by \code{scale}, -whereas the R-level \code{stats::rexp} is parameterized by \code{rate}. +whereas the R-level \code{stats::rexp} is parameterized by \code{rate}. Consult \href{http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Distribution-functions}{Distribution Functions} for more details on the parameterization used for these sugar functions. @@ -568,13 +568,13 @@ is given here: template class VectorBase { public: - struct r_type : + struct r_type : traits::integral_constant{}; struct can_have_na : traits::integral_constant{}; - - typedef typename - traits::storage_type::type + + typedef typename + traits::storage_type::type stored_type; VECTOR& get_ref(){ @@ -586,18 +586,18 @@ public: this)->operator[](i); } - inline int size() const { + inline int size() const { return static_cast( - this)->size(); + this)->size(); } /* definition ommited here */ class iterator; - inline iterator begin() const { - return iterator(*this, 0); + inline iterator begin() const { + return iterator(*this, 0); } - inline iterator end() const { + inline iterator end() const { return iterator(*this, size()); } } @@ -633,27 +633,27 @@ the template class `Rcpp::sugar::Sapply` is given below: template class Sapply : public VectorBase< - Rcpp::traits::r_sexptype_traits< typename + Rcpp::traits::r_sexptype_traits< typename ::Rcpp::traits::result_of::type >::rtype, true, Sapply > { public: - typedef typename + typedef typename ::Rcpp::traits::result_of::type; - + const static int RESULT_R_TYPE = Rcpp::traits::r_sexptype_traits< result_type>::rtype; - + typedef Rcpp::VectorBase VEC; - - typedef typename + + typedef typename Rcpp::traits::r_vector_element_converter< RESULT_R_TYPE>::type converter_type; - + typedef typename Rcpp::traits::storage_type< RESULT_R_TYPE>::type STORAGE; @@ -663,9 +663,9 @@ public: inline STORAGE operator[]( int i ) const { return converter_type::get(fun(vec[i])); } - - inline int size() const { - return vec.size(); + + inline int size() const { + return vec.size(); } private: @@ -675,13 +675,13 @@ private: // sugar -template inline sugar::Sapply sapply(const Rcpp::VectorBase& t, Function fun) { - - return + + return sugar::Sapply(t, fun); } ``` @@ -703,8 +703,8 @@ template class queries the template argument via the `Rcpp::traits::result_of` template. ```cpp -typedef typename - ::Rcpp::traits::result_of::type +typedef typename + ::Rcpp::traits::result_of::type result_type; ``` @@ -717,7 +717,7 @@ struct result_of{ typedef typename T::result_type type; }; -template struct result_of { typedef RESULT_TYPE type; @@ -762,7 +762,7 @@ of a `REALSXP` expression is `double`. ```cpp typedef typename - Rcpp::traits::storage_type::type + Rcpp::traits::storage_type::type STORAGE; ``` @@ -785,7 +785,7 @@ template class Sapply : public VectorBase< Rcpp::traits::r_sexptype_traits< - typename + typename ::Rcpp::traits::result_of::type >::rtype, true, @@ -799,13 +799,13 @@ is the manifestation of the _CRTP_. ### Constructor - + The constructor of the `Sapply` class template is straightforward, it simply consists of holding the reference to the input expression and the function. ```cpp -Sapply(const VEC& vec_, Function fun_): +Sapply(const VEC& vec_, Function fun_): vec(vec_), fun(fun_){} private: @@ -825,8 +825,8 @@ and the converter. Both these methods are inline to maximize performance: inline STORAGE operator[](int i) const { return converter_type::get(fun(vec[i])); } -inline int size() const { - return vec.size(); +inline int size() const { + return vec.size(); } ```