[Rcpp-devel] returning std::pair using Rcpp

Dirk Eddelbuettel edd at debian.org
Mon Oct 10 16:45:47 CEST 2011


On 10 October 2011 at 12:26, Jelmer Ypma wrote:
| 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?

Quite possibly, yes. Contributions welcome.

Dirk
 
| 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()
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list