Welcoming C++14

January 19, 2015

(This article was first published on R Enthusiast and R/C++ hero, and kindly contributed to R-bloggers)

Since last CRAN release of Rcpp11, I’ve started to work on the next iteration of R/C++ support with Rcpp14 by propagating changes to both implementations, e.g. the Strict class that I mentionned in this post.

But now, I’m starting to make unique changes to Rcpp14 for things that require C++14, which is the whole point. These should have no effect for typical uses, but will definitely make the code base more manageable.

One such feature is the auto deduction of function return types in C++14. C++11 does not have that feature so we ended up manually declaring the return type in many places. Here is for example how ifelse is implemented in Rcpp11:

inline auto ifelse( const Cond& cond, const Expr1& expr1, const Expr2& expr2 ) ->  
    decltype(mapply( sugar::ifelse_op(), cond, expr1, expr2)) 
    return mapply( sugar::ifelse_op(), cond, expr1, expr2) ;

The return type is easier to declare using the auto ... -> decltype(...) construct already, but auto return type deduction in C++14 goes further and lets us implement ifelse like this:

inline auto ifelse( const Cond& cond, const Expr1& expr1, const Expr2& expr2 ) {  
    return mapply( sugar::ifelse_op(), cond, expr1, expr2) ;

This is minor, and again with no consequence to the end user, but things like this will make Rcpp14 even nicer to develop than Rcpp11.

To leave a comment for the author, please follow the link and comment on their blog: R Enthusiast and R/C++ hero.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)