[Rcpp-devel] RCPP_EXPORT_CLASS(std::vector<T>)

Greg Minshall minshall at umich.edu
Wed Mar 6 00:45:52 CET 2013


hi.  this is just me reporting on a learning exercise, in case it might
be of help to someone else.  the summary is that one might need to
expose the types of member classes (in particular, *vector* types) of
classes that are being exported with the RCPP_EXPOSED_CLASS directive.

in compiling the following program, it did *not* compile (error messages
below) when the "XXX KEY LINE" was *not* included.  but, including that
line allows the code to compile.
----
#include <R.h>
#include <RcppCommon.h>
#include <Rcpp/S4.h>

class cluster {
public:
    int cells;
};

class cluslist {
public:
    std::vector<cluster> list;
};

#include <Rcpp.h>

RCPP_EXPOSED_CLASS(cluster)
RCPP_EXPOSED_CLASS_NODECL(std::vector<cluster>) // XXX KEY LINE!!!
RCPP_EXPOSED_CLASS(cluslist)

using namespace Rcpp;
RCPP_MODULE(cluster_module) {
    class_<cluster>("cluster")
        .constructor()
        .field_readonly("cells", &cluster::cells);
    class_<cluslist>("cluslist")
        .field("list", &cluslist::list);
};
----

i had thought that, knowing how to wrap<cluster>, Rcpp::Module would be
able to wrap<std::vector<cluster>>, but it can't.  with *non-module*
wraps, Rcpp *does* know how to wrap<std::vector<cluster>> (but cannot
as<std::vector<cluster>> -- since, i believe, the call graph of template
function calls cannot contain a cycle).

error messages (really meant for google searches):
----
.../include/Rcpp/internal/wrap.h: In function 'SEXPREC* Rcpp::internal::range_wrap_dispatch(InputIterator, InputIterator) [with InputIterator = __gnu_cxx::__normal_iterator<const cluster*, std::vector<cluster, std::allocator<cluster> > >, T = cluster]':
.../include/Rcpp/internal/wrap.h:335:   instantiated from 'SEXPREC* Rcpp::internal::range_wrap(InputIterator, InputIterator) [with InputIterator = __gnu_cxx::__normal_iterator<const cluster*, std::vector<cluster, std::allocator<cluster> > >]'
.../include/Rcpp/internal/wrap.h:451:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_iterable__logical(const T&, Rcpp::traits::false_type) [with T = std::vector<cluster, std::allocator<cluster> >]'
.../include/Rcpp/internal/wrap.h:458:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_iterable__matrix_interface(const T&, Rcpp::traits::false_type) [with T = std::vector<cluster, std::allocator<cluster> >]'
.../include/Rcpp/internal/wrap.h:562:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_iterable(const T&, Rcpp::traits::true_type) [with T = std::vector<cluster, std::allocator<cluster> >]'
.../include/Rcpp/internal/wrap.h:639:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown(const T&, Rcpp::traits::false_type) [with T = std::vector<cluster, std::allocator<cluster> >]'
.../include/Rcpp/internal/wrap.h:670:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const T&, Rcpp::traits::false_type) [with T = std::vector<cluster, std::allocator<cluster> >]'
.../include/Rcpp/internal/wrap.h:685:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_importable(const T&, Rcpp::traits::false_type) [with T = std::vector<cluster, std::allocator<cluster> >]'
.../include/Rcpp/internal/wrap.h:703:   instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch(const T&, Rcpp::traits::wrap_type_unknown_tag) [with T = std::vector<cluster, std::allocator<cluster> >]'
.../include/Rcpp/internal/wrap.h:807:   instantiated from 'SEXPREC* Rcpp::wrap(const T&) [with T = cluster_v]'
../cluster.h:371:   instantiated from here
.../include/Rcpp/internal/wrap.h:325: error: no matching function for call to 'range_wrap_dispatch___impl(__gnu_cxx::__normal_iterator<const cluster*, std::vector<cluster, std::allocator<cluster> > >&, __gnu_cxx::__normal_iterator<const cluster*, std::vector<cluster, std::allocator<cluster> > >&, Rcpp::traits::r_type_module_object_tag)'
----

cheers, Greg


More information about the Rcpp-devel mailing list