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{
47
47
operator bool () const { return ::Rcpp::as<bool >(get ()) ; }
48
48
operator int () const { return ::Rcpp::as<int >(get ()) ; }
49
49
50
+ inline void move (R_xlen_t n) { index += n ; }
51
+
50
52
const VECTOR* parent;
51
53
R_xlen_t index ;
52
54
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ namespace internal{
40
40
* @param v reference to the associated character vector
41
41
* @param index index
42
42
*/
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_){}
44
44
45
45
const_string_proxy (SEXP x): parent(0 ), index(0 ) {
46
46
Vector<RTYPE> tmp (x);
Original file line number Diff line number Diff line change @@ -249,6 +249,13 @@ namespace traits {
249
249
template <> struct r_vector_iterator <VECSXP> : proxy_based_iterator<VECSXP>{} ;
250
250
template <> struct r_vector_iterator <EXPRSXP> : proxy_based_iterator<EXPRSXP>{} ;
251
251
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>{} ;
252
259
253
260
} // traits
254
261
}
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ namespace traits{
67
67
}
68
68
inline iterator get () const { return iterator ( proxy (*p, 0 ) ) ;}
69
69
// 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 ) ) ; }
71
71
72
72
inline proxy ref () { return proxy (*p,0 ) ; }
73
73
inline proxy ref (R_xlen_t i) { return proxy (*p,i);}
Original file line number Diff line number Diff line change @@ -574,13 +574,31 @@ std::string character_iterator1( CharacterVector letters ){
574
574
return res ;
575
575
}
576
576
577
+ // [[Rcpp::export]]
578
+ std::string character_const_iterator1 ( const CharacterVector letters ){
579
+ std::string res ;
580
+ CharacterVector::const_iterator first = letters.begin () ;
581
+ CharacterVector::const_iterator last = letters.end () ;
582
+ while ( first != last ){
583
+ res += *first ;
584
+ ++first ;
585
+ }
586
+ return res ;
587
+ }
588
+
577
589
578
590
// [[Rcpp::export]]
579
591
std::string character_iterator2 ( CharacterVector letters ){
580
592
std::string res (std::accumulate (letters.begin (), letters.end (), std::string ()));
581
593
return res ;
582
594
}
583
595
596
+ // [[Rcpp::export]]
597
+ std::string character_const_iterator2 ( const CharacterVector letters ){
598
+ std::string res (std::accumulate (letters.begin (), letters.end (), std::string ()));
599
+ return res ;
600
+ }
601
+
584
602
// [[Rcpp::export]]
585
603
CharacterVector character_reverse ( CharacterVector y ){
586
604
std::reverse ( y.begin (), y.end () ) ;
Original file line number Diff line number Diff line change @@ -499,6 +499,18 @@ if (.runThisTest) {
499
499
paste(letters , collapse = " " ),
500
500
msg = " CharacterVector::iterator using std::accumulate" )
501
501
}
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
+ }
502
514
503
515
test.CharacterVector.reverse <- function (){
504
516
fun <- character_reverse
You can’t perform that action at this time.
0 commit comments