[Rcpp-devel] returning std::pair using Rcpp
Jelmer Ypma
jelmerypma at gmail.com
Mon Oct 10 13:26:44 CEST 2011
Dear list,
I tried to return a std::pair using Rcpp and inline (see example
below), but didn't succeed. Returning a std::map works fine. Does
anyone know whether this does not work because Rcpp::wrap has not been
implemented for std::pair or because I'm doing something else wrong?
The error I get when compiling funx_pair is:
In function 'SEXPREC*
Rcpp::internal::wrap_dispatch_unknown_iterable(const T&,
Rcpp::traits::false_type) [with T = std::pair<std::basic_string<char>,
int>, SEXPREC* = SEXPREC*, Rcpp::traits::false_type =
Rcpp::traits::integral_constant<bool, false>]':
Many thanks in advance,
Jelmer
library('inline')
library('Rcpp')
includes <- '
#include <utility> // USES map, pair
'
# return a std::map (modified from the unit tests)
src_map <- '
std::map<std::string, int> m;
m["a"] = 2;
m["b"] = 3;
m["c"] = 1;
return Rcpp::wrap( m );
'
funx_map <- cxxfunction( signature(), body=src_map, includes=includes,
plugin='Rcpp', verbose=TRUE )
funx_map()
# try to return a std::pair
src_pair <- '
std::pair<std::string, int> m( "a" , 2 );
return Rcpp::wrap( m );
'
funx_pair <- cxxfunction( signature(), body=src_pair,
includes=includes, plugin='Rcpp', verbose=TRUE )
funx_pair()
More information about the Rcpp-devel
mailing list