Skip to content

Commit 48f70ba

Browse files
author
Qiang Kou
committed
vector fixed
1 parent 6bd4fee commit 48f70ba

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

inst/include/Rcpp/api/meat/wrap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ namespace internal{
2828
template <typename InputIterator, typename KEY, typename VALUE, int RTYPE>
2929
inline SEXP range_wrap_dispatch___impl__pair( InputIterator first, InputIterator last, Rcpp::traits::true_type ){
3030
RCPP_DEBUG_3( "range_wrap_dispatch___impl__pair<KEY = %s, VALUE = %s, RTYPE = %d>\n", DEMANGLE(KEY), DEMANGLE(VALUE), RTYPE)
31-
size_t size = std::distance( first, last ) ;
31+
R_xlen_t size = std::distance( first, last ) ;
3232
//typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
3333

3434
CharacterVector names(size) ;
3535
Vector<RTYPE> x(size) ;
3636
Rcpp::String buffer ;
37-
for( size_t i = 0; i < size ; i++, ++first){
37+
for( R_xlen_t i = 0; i < size ; i++, ++first){
3838
buffer = first->first ;
3939
x[i] = first->second ;
4040
names[i] = buffer ;
@@ -45,12 +45,12 @@ inline SEXP range_wrap_dispatch___impl__pair( InputIterator first, InputIterator
4545

4646
template <typename InputIterator, typename KEY, typename VALUE, int RTYPE>
4747
inline SEXP range_wrap_dispatch___impl__pair( InputIterator first, InputIterator last, Rcpp::traits::false_type ){
48-
size_t size = std::distance( first, last ) ;
48+
R_xlen_t size = std::distance( first, last ) ;
4949

5050
Shield<SEXP> names( Rf_allocVector(STRSXP, size) ) ;
5151
Shield<SEXP> x( Rf_allocVector(VECSXP, size) ) ;
5252
Rcpp::String buffer ;
53-
for( size_t i = 0; i < size ; i++, ++first){
53+
for( R_xlen_t i = 0; i < size ; i++, ++first){
5454
buffer = first->first ;
5555
SET_VECTOR_ELT( x, i, Rcpp::wrap(first->second) );
5656
SET_STRING_ELT( names, i, buffer.get_sexp() ) ;

inst/include/Rcpp/vector/Vector.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ class Vector :
8989
fill( u ) ;
9090
}
9191

92+
explicit 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)
94+
Storage::set__( Rf_allocVector( RTYPE, size) ) ;
95+
fill( u ) ;
96+
}
97+
9298
// constructor for CharacterVector()
9399
Vector( const std::string& st ){
94100
RCPP_DEBUG_2( "Vector<%d>( const std::string& = %s )", RTYPE, st.c_str() )
@@ -101,7 +107,7 @@ class Vector :
101107
Storage::set__(internal::vector_from_string<RTYPE>(st) ) ;
102108
}
103109

104-
Vector( const int& siz, stored_type (*gen)(void) ) {
110+
explicit Vector( const int& siz, stored_type (*gen)(void) ) {
105111
RCPP_DEBUG_2( "Vector<%d>( const int& siz = %s, stored_type (*gen)(void) )", RTYPE, siz )
106112
Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
107113
std::generate( begin(), end(), gen );
@@ -162,6 +168,12 @@ class Vector :
162168
Storage::set__( Rf_allocVector( RTYPE, size) ) ;
163169
fill_or_generate( u ) ;
164170
}
171+
template <typename U>
172+
Vector( const int& size, const U& u) {
173+
RCPP_DEBUG_2( "Vector<%d>( const int& size, const U& u )", RTYPE, size )
174+
Storage::set__( Rf_allocVector( RTYPE, size) ) ;
175+
fill_or_generate( u ) ;
176+
}
165177
template <bool NA, typename T>
166178
Vector( const sugar::SingleLogicalResult<NA,T>& obj ) {
167179
Storage::set__( r_cast<RTYPE>( const_cast<sugar::SingleLogicalResult<NA,T>&>(obj).get_sexp() ) ) ;

0 commit comments

Comments
 (0)