@@ -83,14 +83,10 @@ class Vector :
8383 Storage::set__ ( Rf_allocVector ( RTYPE, obj.get () ) ) ;
8484 }
8585
86- Vector ( const R_xlen_t& size, const stored_type& u ) {
87- RCPP_DEBUG_2 ( " Vector<%d>( const R_xlen_t& size = %d, const stored_type& u )" , RTYPE, size)
88- Storage::set__ ( Rf_allocVector ( RTYPE, size) ) ;
89- fill ( u ) ;
90- }
91-
92- Vector ( const int & size, const stored_type& u ) {
93- RCPP_DEBUG_2 ( " Vector<%d>( const R_xlen_t& size = %d, const stored_type& u )" , RTYPE, size)
86+ template <typename T>
87+ Vector ( const T& size, const stored_type& u,
88+ typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void >::type* = 0 ) {
89+ RCPP_DEBUG_2 ( " Vector<%d>( const T& size = %d, const stored_type& u )" , RTYPE, size)
9490 Storage::set__ ( Rf_allocVector ( RTYPE, size) ) ;
9591 fill ( u ) ;
9692 }
@@ -107,17 +103,13 @@ class Vector :
107103 Storage::set__ (internal::vector_from_string<RTYPE>(st) ) ;
108104 }
109105
110- Vector ( const int & siz, stored_type (*gen)(void ) ) {
106+ template <typename T>
107+ Vector ( const T& siz, stored_type (*gen)(void ),
108+ typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void >::type* = 0 ) {
111109 RCPP_DEBUG_2 ( " Vector<%d>( const int& siz = %s, stored_type (*gen)(void) )" , RTYPE, siz )
112110 Storage::set__ ( Rf_allocVector ( RTYPE, siz) ) ;
113111 std::generate ( begin (), end (), gen );
114112 }
115-
116- Vector ( const R_xlen_t& siz, stored_type (*gen)(void ) ) {
117- RCPP_DEBUG_2 ( " Vector<%d>( const R_xlen_t& siz = %s, stored_type (*gen)(void) )" , RTYPE, siz )
118- Storage::set__ ( Rf_allocVector ( RTYPE, siz) ) ;
119- std::generate ( begin (), end (), gen );
120- }
121113
122114 // Add template class T and then restict T to arithmetic.
123115 template <typename T>
@@ -160,44 +152,44 @@ class Vector :
160152 RCPP_DEBUG_2 ( " Vector<%d>( const VectorBase<RTYPE,NA,VEC>& ) [VEC = %s]" , RTYPE, DEMANGLE (VEC) )
161153 import_sugar_expression ( other, typename traits::same_type<Vector,VEC>::type () ) ;
162154 }
163- template <typename U>
164- Vector ( const R_xlen_t& size, const U& u) {
165- RCPP_DEBUG_2 ( " Vector<%d>( const R_xlen_t& size, const U& u )" , RTYPE, size )
166- Storage::set__ ( Rf_allocVector ( RTYPE, size) ) ;
167- fill_or_generate ( u ) ;
168- }
169- template <typename U>
170- Vector ( const int & size, const U& u) {
171- RCPP_DEBUG_2 ( " Vector<%d>( const int& size, const U& u )" , RTYPE, size )
155+
156+ template <typename T, typename U>
157+ Vector ( const T& size, const U& u,
158+ typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void >::type* = 0 ) {
159+ RCPP_DEBUG_2 ( " Vector<%d>( const T& size, const U& u )" , RTYPE, size )
172160 Storage::set__ ( Rf_allocVector ( RTYPE, size) ) ;
173161 fill_or_generate ( u ) ;
174162 }
163+
175164 template <bool NA, typename T>
176165 Vector ( const sugar::SingleLogicalResult<NA,T>& obj ) {
177166 Storage::set__ ( r_cast<RTYPE>( const_cast <sugar::SingleLogicalResult<NA,T>&>(obj).get_sexp () ) ) ;
178167 RCPP_DEBUG_2 ( " Vector<%d>( const sugar::SingleLogicalResult<NA,T>& ) [T = %s]" , RTYPE, DEMANGLE (T) )
179168 }
180169
181- template <typename U1>
182- Vector ( const R_xlen_t& siz, stored_type (*gen)(U1), const U1& u1) {
170+ template <typename T, typename U1>
171+ Vector ( const T& siz, stored_type (*gen)(U1), const U1& u1,
172+ typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void >::type* = 0 ) {
183173 Storage::set__ ( Rf_allocVector ( RTYPE, siz) ) ;
184- RCPP_DEBUG_2 ( " const R_xlen_t & siz, stored_type (*gen)(U1), const U1& u1 )" , RTYPE, siz )
174+ RCPP_DEBUG_2 ( " const T & siz, stored_type (*gen)(U1), const U1& u1 )" , RTYPE, siz )
185175 iterator first = begin (), last = end () ;
186176 while ( first != last ) *first++ = gen (u1) ;
187177 }
188178
189- template <typename U1, typename U2>
190- Vector ( const R_xlen_t& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2) {
179+ template <typename T, typename U1, typename U2>
180+ Vector ( const T& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2,
181+ typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void >::type* = 0 ) {
191182 Storage::set__ ( Rf_allocVector ( RTYPE, siz) ) ;
192- RCPP_DEBUG_2 ( " const R_xlen_t & siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2)" , RTYPE, siz )
183+ RCPP_DEBUG_2 ( " const T & siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2)" , RTYPE, siz )
193184 iterator first = begin (), last = end () ;
194185 while ( first != last ) *first++ = gen (u1,u2) ;
195186 }
196187
197- template <typename U1, typename U2, typename U3>
198- Vector ( const R_xlen_t& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3) {
188+ template <typename T, typename U1, typename U2, typename U3>
189+ Vector ( const T& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3,
190+ typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void >::type* = 0 ) {
199191 Storage::set__ ( Rf_allocVector ( RTYPE, siz) ) ;
200- RCPP_DEBUG_2 ( " const R_xlen_t & siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3)" , RTYPE, siz )
192+ RCPP_DEBUG_2 ( " const T & siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3)" , RTYPE, siz )
201193 iterator first = begin (), last = end () ;
202194 while ( first != last ) *first++ = gen (u1,u2,u3) ;
203195 }
@@ -209,10 +201,11 @@ class Vector :
209201 std::copy ( first, last, begin () ) ;
210202 }
211203
212- template <typename InputIterator>
213- Vector ( InputIterator first, InputIterator last, R_xlen_t n) {
204+ template <typename InputIterator, typename T>
205+ Vector ( InputIterator first, InputIterator last, T n,
206+ typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void >::type* = 0 ) {
214207 Storage::set__ (Rf_allocVector (RTYPE, n)) ;
215- RCPP_DEBUG_2 ( " Vector<%d>( InputIterator first, InputIterator last, R_xlen_t n = %d)" , RTYPE, n )
208+ RCPP_DEBUG_2 ( " Vector<%d>( InputIterator first, InputIterator last, T n = %d)" , RTYPE, n )
216209 std::copy ( first, last, begin () ) ;
217210 }
218211
@@ -223,10 +216,11 @@ class Vector :
223216 std::transform ( first, last, begin (), func) ;
224217 }
225218
226- template <typename InputIterator, typename Func>
227- Vector ( InputIterator first, InputIterator last, Func func, R_xlen_t n){
219+ template <typename InputIterator, typename Func, typename T>
220+ Vector ( InputIterator first, InputIterator last, Func func, T n,
221+ typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void >::type* = 0 ){
228222 Storage::set__ ( Rf_allocVector ( RTYPE, n ) );
229- RCPP_DEBUG_2 ( " Vector<%d>( InputIterator, InputIterator, Func, R_xlen_t n = %d )" , RTYPE, n )
223+ RCPP_DEBUG_2 ( " Vector<%d>( InputIterator, InputIterator, Func, T n = %d )" , RTYPE, n )
230224 std::transform ( first, last, begin (), func) ;
231225 }
232226
0 commit comments