-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
const'ness (constivity?) in sugar::min/max #477
Comments
So the reverse dependency check threw out two new failures:
I tried applying the first suggested changeset here it didn't succeed. |
|
Analogous diff for min diff --git a/inst/include/Rcpp/sugar/functions/min.h b/inst/include/Rcpp/sugar/functions/min.h
index 0dd8c2c..3e83a76 100644
--- a/inst/include/Rcpp/sugar/functions/min.h
+++ b/inst/include/Rcpp/sugar/functions/min.h
@@ -45,6 +45,20 @@ namespace sugar{
return min_ ;
}
+ operator STORAGE() const {
+ STORAGE min, current ;
+ min = obj[0] ;
+ if( Rcpp::traits::is_na<RTYPE>( min ) ) return min ;
+
+ R_xlen_t n = obj.size() ;
+ for( R_xlen_t i=1; i<n; i++){
+ current = obj[i] ;
+ if( Rcpp::traits::is_na<RTYPE>( current ) ) return current;
+ if( current < min ) min = current ;
+ }
+ return min ;
+ }
+
const T& obj ;
STORAGE min_, max_, current ;
} ;
@@ -68,6 +82,18 @@ namespace sugar{
return min_ ;
}
+ operator STORAGE() const {
+ STORAGE min, current ;
+ min = obj[0] ;
+
+ R_xlen_t n = obj.size() ;
+ for( R_xlen_t i=1; i<n; i++){
+ current = obj[i] ;
+ if( current < min ) min = current ;
+ }
+ return min ;
+ }
+
const T& obj ;
STORAGE min_, current ;
} ;
|
Thanks. Had hand-cobbled diff for min in by now too. Both CARBayesST and nonlinearTseries now pass. All good. I guess ... you should wrap this up as a new PR. |
I can do that...do you want the "extra complicated V1" as evidenced in the diffs? |
No strong feeling either way. If we have the const variants now not using the private member variables, maybe we should clean up the non-const versions? |
I think so...I'll do that. It's a trivial change. |
Done in #478 |
The
sugar::min
andsugar::max
classes (which to my mind should just be functions anyhow, but leaving that) have a cast operator to the typedef'edSTORAGE
type. This operator is not defined asconst
because it actually modifies someprivate
member variables. This is causing a problem with the latest fix for operator ambiguity inMatrix
orVector
arithmetic operators.I see no problem in moving these
private
member variables simply into the cast operator function and declaring the function asconst
. Does anyone else see any pitfalls?I would propose changing:
to
Alternatively, we could greatly simplify
min/max
by simply defining:The text was updated successfully, but these errors were encountered: