Welcoming C++14

[This article was first published on R Enthusiast and R/C++ hero, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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:

template <typename Cond, typename Expr1, typename Expr2>  
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:

template <typename Cond, typename Expr1, typename Expr2>  
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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)