File tree Expand file tree Collapse file tree 6 files changed +41
-2
lines changed
Expand file tree Collapse file tree 6 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ namespace internal{
4747 operator bool () const { return ::Rcpp::as<bool >(get ()) ; }
4848 operator int () const { return ::Rcpp::as<int >(get ()) ; }
4949
50+ inline void move (R_xlen_t n) { index += n ; }
51+
5052 const VECTOR* parent;
5153 R_xlen_t index ;
5254
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ namespace internal{
4040 * @param v reference to the associated character vector
4141 * @param index index
4242 */
43- const_string_proxy ( VECTOR& v, R_xlen_t index_ ) : parent(&v), index(index_){}
43+ const_string_proxy ( const VECTOR& v, R_xlen_t index_ ) : parent(&v), index(index_){}
4444
4545 const_string_proxy (SEXP x): parent(0 ), index(0 ) {
4646 Vector<RTYPE> tmp (x);
Original file line number Diff line number Diff line change @@ -249,6 +249,13 @@ namespace traits {
249249 template <> struct r_vector_iterator <VECSXP> : proxy_based_iterator<VECSXP>{} ;
250250 template <> struct r_vector_iterator <EXPRSXP> : proxy_based_iterator<EXPRSXP>{} ;
251251 template <> struct r_vector_iterator <STRSXP> : proxy_based_iterator<STRSXP>{} ;
252+
253+ template <int RTYPE> struct proxy_based_const_iterator {
254+ typedef ::Rcpp::internal::Proxy_Iterator< typename r_vector_const_proxy<RTYPE>::type > type ;
255+ } ;
256+ template <> struct r_vector_const_iterator <VECSXP> : proxy_based_const_iterator<VECSXP>{} ;
257+ template <> struct r_vector_const_iterator <EXPRSXP> : proxy_based_const_iterator<EXPRSXP>{} ;
258+ template <> struct r_vector_const_iterator <STRSXP> : proxy_based_const_iterator<STRSXP>{} ;
252259
253260} // traits
254261}
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ namespace traits{
6767 }
6868 inline iterator get () const { return iterator ( proxy (*p, 0 ) ) ;}
6969 // inline const_iterator get_const() const { return const_iterator( *p ) ;}
70- inline const_iterator get_const () const { return get_vector_ptr (*p ) ; }
70+ inline const_iterator get_const () const { return const_iterator ( const_proxy (*p, 0 ) ) ; }
7171
7272 inline proxy ref () { return proxy (*p,0 ) ; }
7373 inline proxy ref (R_xlen_t i) { return proxy (*p,i);}
Original file line number Diff line number Diff line change @@ -576,13 +576,31 @@ std::string character_iterator1( CharacterVector letters ){
576576 return res ;
577577}
578578
579+ // [[Rcpp::export]]
580+ std::string character_const_iterator1 ( const CharacterVector letters ){
581+ std::string res ;
582+ CharacterVector::const_iterator first = letters.begin () ;
583+ CharacterVector::const_iterator last = letters.end () ;
584+ while ( first != last ){
585+ res += *first ;
586+ ++first ;
587+ }
588+ return res ;
589+ }
590+
579591
580592// [[Rcpp::export]]
581593std::string character_iterator2 ( CharacterVector letters ){
582594 std::string res (std::accumulate (letters.begin (), letters.end (), std::string ()));
583595 return res ;
584596}
585597
598+ // [[Rcpp::export]]
599+ std::string character_const_iterator2 ( const CharacterVector letters ){
600+ std::string res (std::accumulate (letters.begin (), letters.end (), std::string ()));
601+ return res ;
602+ }
603+
586604// [[Rcpp::export]]
587605CharacterVector character_reverse ( CharacterVector y ){
588606 std::reverse ( y.begin (), y.end () ) ;
Original file line number Diff line number Diff line change @@ -499,6 +499,18 @@ if (.runThisTest) {
499499 paste(letters , collapse = " " ),
500500 msg = " CharacterVector::iterator using std::accumulate" )
501501 }
502+
503+ test.CharacterVector.iterator <- function (){
504+ fun <- character_const_iterator1
505+ checkEquals(fun(letters ),
506+ paste(letters , collapse = " " ),
507+ msg = " CharacterVector::iterator explicit looping" )
508+
509+ fun <- character_const_iterator2
510+ checkEquals(fun(letters ),
511+ paste(letters , collapse = " " ),
512+ msg = " CharacterVector::iterator using std::accumulate" )
513+ }
502514
503515 test.CharacterVector.reverse <- function (){
504516 fun <- character_reverse
You can’t perform that action at this time.
0 commit comments