diff --git a/inst/include/Rcpp/sugar/functions/max.h b/inst/include/Rcpp/sugar/functions/max.h index 41d5de539..f366f35c7 100644 --- a/inst/include/Rcpp/sugar/functions/max.h +++ b/inst/include/Rcpp/sugar/functions/max.h @@ -32,22 +32,22 @@ namespace sugar{ Max( const T& obj_) : obj(obj_) {} - operator STORAGE() { - max_ = obj[0] ; - if( Rcpp::traits::is_na( max_ ) ) return max_ ; + operator STORAGE() const { + STORAGE max, current ; + max = obj[0] ; + if( Rcpp::traits::is_na( max ) ) return max ; R_xlen_t n = obj.size() ; for( R_xlen_t i=1; i( current ) ) return current; - if( current > max_ ) max_ = current ; + if( current > max ) max = current ; } - return max_ ; + return max ; } private: const T& obj ; - STORAGE min_, max_, current ; } ; // version for NA = false @@ -58,20 +58,20 @@ namespace sugar{ Max( const T& obj_) : obj(obj_) {} - operator STORAGE() { - max_ = obj[0] ; + operator STORAGE() const { + STORAGE max, current ; + max = obj[0] ; R_xlen_t n = obj.size() ; for( R_xlen_t i=1; i max_ ) max_ = current ; + if( current > max ) max = current ; } - return max_ ; + return max ; } private: const T& obj ; - STORAGE max_, current ; } ; diff --git a/inst/include/Rcpp/sugar/functions/min.h b/inst/include/Rcpp/sugar/functions/min.h index 0dd8c2c29..19f577f24 100644 --- a/inst/include/Rcpp/sugar/functions/min.h +++ b/inst/include/Rcpp/sugar/functions/min.h @@ -32,21 +32,21 @@ namespace sugar{ Min( const T& obj_) : obj(obj_) {} - operator STORAGE() { - min_ = obj[0] ; - if( Rcpp::traits::is_na( min_ ) ) return min_ ; + operator STORAGE() const { + STORAGE min, current ; + min = obj[0] ; + if( Rcpp::traits::is_na( min ) ) return min ; R_xlen_t n = obj.size() ; for( R_xlen_t i=1; i( current ) ) return current; - if( current < min_ ) min_ = current ; + if( current < min ) min = current ; } - return min_ ; + return min ; } const T& obj ; - STORAGE min_, max_, current ; } ; // version for NA = false @@ -57,19 +57,19 @@ namespace sugar{ Min( const T& obj_) : obj(obj_) {} - operator STORAGE() { - min_ = obj[0] ; + operator STORAGE() const { + STORAGE min, current ; + min = obj[0] ; R_xlen_t n = obj.size() ; for( R_xlen_t i=1; i