@@ -59,6 +59,36 @@ class Grabber{
5959 int index ;
6060} ;
6161
62+ // we define a different Table class depending on whether we are using
63+ // std::map or not
64+ #ifdef RCPP_USING_MAP
65+
66+ template <int RTYPE, typename TABLE_T>
67+ class Table {
68+ public:
69+ typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
70+
71+ Table ( const TABLE_T& table ): hash() {
72+ std::for_each ( table.begin (), table.end (), Inserter (hash) ) ;
73+ }
74+
75+ inline operator IntegerVector () const {
76+ int n = hash.size () ;
77+ IntegerVector result = no_init (n) ;
78+ CharacterVector names = no_init (n) ;
79+ std::for_each ( hash.begin (), hash.end (), Grabber<HASH, RTYPE>(result, names) ) ;
80+ result.names () = names ;
81+ return result ;
82+ }
83+
84+ private:
85+ typedef RCPP_UNORDERED_MAP<STORAGE, int , MapCompare<STORAGE> >HASH ;
86+ typedef CountInserter<HASH,STORAGE> Inserter ;
87+ HASH hash ;
88+ };
89+
90+ #else
91+
6292template <int RTYPE, typename TABLE_T>
6393class Table {
6494public:
@@ -83,20 +113,16 @@ class Table {
83113 }
84114
85115private:
86- // bugfix for standard map
87- #ifdef RCPP_USING_MAP
88- typedef RCPP_UNORDERED_MAP<STORAGE, int , MapCompare<STORAGE> >HASH ;
89- #else
90- typedef RCPP_UNORDERED_MAP<STORAGE, int > HASH ;
91- #endif
92-
93- typedef CountInserter<HASH,STORAGE> Inserter ;
94-
116+ typedef RCPP_UNORDERED_MAP<STORAGE, int > HASH ;
95117 typedef std::map<STORAGE, int , typename Rcpp::traits::comparator_type<RTYPE>::type > SORTED_MAP ;
96118
97- HASH hash ;
98119 SORTED_MAP map ;
120+
121+ typedef CountInserter<HASH,STORAGE> Inserter ;
122+ HASH hash ;
99123};
124+
125+ #endif // USING_RCPP_MAP
100126
101127} // sugar
102128
0 commit comments