[Rcpp-devel] module can't expose std::map as a field?

Yasir Suhail yusuhail at gmail.com
Tue Dec 20 22:16:56 CET 2011


I saw at http://www.r-bloggers.com/rcpp-0-7-5-2/ that std::map can be
exposed to R since Rcpp 0.7.5.2.

I changed the skeleton module package to add a field:
class World {
public:
    World() : msg("hello"){}
    void set(std::string msg) { this->msg = msg; }
    std::string greet() { return msg; }
    std::map<std::string,int> myMap;
private:
    std::string msg;
};



and then expose it as:

	class_<World>( "World" )
	    // expose the default constructor
	    .constructor()
		.method( "greet", &World::greet , "get the message" )
		.method( "set", &World::set     , "set the message" )
		.field("myMap", &World::myMap)
	;

However, when trying to install the package, it apparently does not work:

** libs
*** arch - x86_64
/opt/local/bin/g++-mp-4.4 -I/opt/local/lib/R/include
-I/opt/local/lib/R/include/x86_64  -I/opt/local/include
-I"/opt/local/lib/R/library/Rcpp/include"   -fPIC  -pipe -O2 -m64 -c
rcpp_module.cpp -o rcpp_module.o
In file included from /opt/local/lib/R/library/Rcpp/include/RcppCommon.h:306,
                 from /opt/local/lib/R/library/Rcpp/include/Rcpp.h:27,
                 from rcpp_module.cpp:1:
/opt/local/lib/R/library/Rcpp/include/Rcpp/traits/Exporter.h: In
constructor 'Rcpp::traits::Exporter<T>::Exporter(SEXPREC*) [with T =
std::map<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int, std::less<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
std::allocator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int> > >]':
/opt/local/lib/R/library/Rcpp/include/Rcpp/as.h:51:   instantiated
from 'T Rcpp::internal::as(SEXPREC*, Rcpp::traits::r_type_generic_tag)
[with T = std::map<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int, std::less<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
std::allocator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int> > >]'
/opt/local/lib/R/library/Rcpp/include/Rcpp/as.h:75:   instantiated
from 'T Rcpp::as(SEXPREC*) [with T = std::map<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int,
std::less<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, std::allocator<std::pair<const
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, int> > >]'
/opt/local/lib/R/library/Rcpp/include/Rcpp/module/Module_Field.h:36:
instantiated from 'void
Rcpp::class_<Class>::CppProperty_Getter_Setter<PROP>::set(Class*,
SEXPREC*) [with PROP = std::map<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int,
std::less<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, std::allocator<std::pair<const
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, int> > >, Class = World]'
rcpp_module.cpp:83:   instantiated from here
/opt/local/lib/R/library/Rcpp/include/Rcpp/traits/Exporter.h:31:
error: no matching function for call to
'std::map<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int, std::less<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
std::allocator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int> >
>::map(SEXPREC*&)'
/opt/local/include/gcc44/c++/bits/stl_map.h:170: note: candidates are:
std::map<_Key, _Tp, _Compare, _Alloc>::map(const std::map<_Key, _Tp,
_Compare, _Alloc>&) [with _Key = std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, _Tp = int, _Compare =
std::less<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, _Alloc = std::allocator<std::pair<const
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, int> >]
/opt/local/include/gcc44/c++/bits/stl_map.h:159: note:
std::map<_Key, _Tp, _Compare, _Alloc>::map(const _Compare&, const
_Alloc&) [with _Key = std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, _Tp = int, _Compare =
std::less<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, _Alloc = std::allocator<std::pair<const
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, int> >]
/opt/local/include/gcc44/c++/bits/stl_map.h:150: note:
std::map<_Key, _Tp, _Compare, _Alloc>::map() [with _Key =
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, _Tp = int, _Compare = std::less<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, _Alloc =
std::allocator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int> >]
make: *** [rcpp_module.o] Error 1
ERROR: compilation failed for package ‘aggloR’



If I am doing something wrong, please let me know. Thanks!


More information about the Rcpp-devel mailing list