[Rcpp-devel] A short note on C++11 and Rcpp

Dirk Eddelbuettel edd at debian.org
Wed Apr 9 14:03:12 CEST 2014


By this time tomorrow R 3.1.0 will be released, and we can turn C++11 support
on in our CRAN packages.  This is more than welcome, and had been a long time
coming. A big thanks to Martyn and others in R Core who made it happen.

And to avoid some confusion: using C++11 requires no changes for Rcpp.
Someone already asked me if one needed a new package to use C++11: not so.

As detailed in the R 3.1.0 version of the Writing R Extension manual, for any
given CRAN package you simply turn on C++11 support by declaring

       CXX_STD = CXX11

in Makevars just like any other compiler directive or declaration. You can
also use a line in DESCRIPTION if you prefer.  There are other declaration
and values one can in src/Makevars; see the manual for the full details.

And can be seen in Rcpp Gallery posts from early 2013 [1], we already have a
plugin for C++11 in Rcpp: Use of C++11 was of course possible for as long as
the compiler supported whichever parts of the standard. The main change now
is that CRAN allows us uploads with C++11.

C++ is a fairly wide and open language (cf Meyer's point about four languages
in C++; this can now be seen as five) which itself makes a strong point about
backwards compatibility. Stroustrup and Sutter (at a joint talk here in
Chicago last fall) see support for C itself as a key reason for early support
of C++. C++ tries hard to support its own evolving past. And C++11 and beyond
now give us even more tools. Continuity of existing interface matter to many
(though clearly not all) of us; and this is no change.  What worked before
continues to work, we now simply have more options which is a very good thing.
We can change implementations and things under the hood, whether we change
interfaces remains our choice is of course not forced. 

And besides the C++11 standard itself, this change also has other benefits of
bringing different changes relative to the very old 1998 standard.  Eg I have
two small packages (RcppCNPy, RcppBDT) both of which I have changed to C++11
simply to finally get support for 'long long'.

Dirk

[1] http://gallery.rcpp.org/tags/c++11/

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list