Dirk released Rcpp 0.7.5 yesterday
The main thing is the smarter wrap function that now uses techniques of type traits and template meta-programming to have a compile time guess at whether an object is wrappable, and how to do it. Currently wrappable types are :
- primitive types : int, double, Rbyte, Rcomplex
- std::string
- STL containers such as std::vector<T> as long as T is wrappable. This is not strictly tied to the STL, actually any type that has a nested type called iterator and member functions begin() and end() will do
- STL maps keyed by strings such as std::map<std::string,T> as long as T is wrappable
- any class that can be implicitely converted to
SEXP
- any class for which the
wrap
template is partly or fully specialized. (The next version of RInside has an example of that)
Here comes an example (from our unit tests) :
funx <- cfunction(signature(), ' std::map< std::string,std::vector<int> > m ; std::vector<int> b ; b.push_back(1) ; b.push_back(2) ; m["b"] = b ; std::vector<int> a ; a.push_back(1) ; a.push_back(2) ; a.push_back(2) ; m["a"] = a ; std::vector<int> c ; c.push_back(1) ; c.push_back(2) ; c.push_back(2) ; c.push_back(2) ; m["c"] = c ; return wrap(m) ; ', Rcpp=TRUE, verbose=FALSE, includes = "using namespace Rcpp;" )
R> funx() $a [1] 1 2 2 $b [1] 1 2 $c [1] 1 2 2 2
Apart from that, other things have changed, here is the relevant section of the NEWS for this release
o wrap has been much improved. wrappable types now are : - primitive types : int, double, Rbyte, Rcomplex, float, bool - std::string - STL containers which have iterators over wrappable types: (e.g. std::vector, std::deque , std::list , etc ...). - STL maps keyed by std::string, e.g std::map<:string> - classes that have implicit conversion to SEXP - classes for which the wrap template if fully or partly specialized This allows composition, so for example this class is wrappable: std::vector< std::map<:string> > (if T is wrappable) o The range based version of wrap is now exposed at the Rcpp:: level with the following interface : Rcpp::wrap( InputIterator first, InputIterator last ) This is dispatched internally to the most appropriate implementation using traits o a new namespace Rcpp::traits has been added to host the various type traits used by wrap o The doxygen documentation now shows the examples o A new file inst/THANKS acknowledges the kind help we got from others o The RcppSexp has been removed from the library. o The methods RObject::asFoo are deprecated and will be removed in the next version. The alternative is to use as . o The method RObject::slot can now be used to get or set the associated slot. This is one more example of the proxy pattern o Rcpp::VectorBase gains a names() method that allows getting/setting the names of a vector. This is yet another example of the proxy pattern. o Rcpp::DottedPair gains templated operator<< and operator>> that allow wrap and push_back or wrap and push_front of an object o Rcpp::DottedPair, Rcpp::Language, Rcpp::Pairlist are less dependent on C++0x features. They gain constructors with up to 5 templated arguments. 5 was choosed arbitrarily and might be updated upon request. o function calls by the Rcpp::Function class is less dependent on C++0x. It is now possible to call a function with up to 5 templated arguments (candidate for implicit wrap) o added support for 64-bit Windows (thanks to Brian Ripley and Uwe Ligges)