-
-
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
Nullable object (closes #363) #368
Conversation
Given that |
You could you be "not set" but "not null" ? Wait. I think I get it now. That is a good idea. Adding ... |
* @throw 'not initialized' if object has not been set | ||
*/ | ||
inline operator SEXP() { | ||
isSet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be checkIfSet()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. Now fixed.
I blame @dcdillon for enticing me to make changes, which I then changed midflight... ;-)
My only thought: the class name EDIT: Just saw your comment re: why you didn't go that route... it's a shame; I wonder if there's some other fix. I'm still not quite sure on the utility -- can you provide some other examples where this would be used? (The example in #363 was a bit bare bones; a full example would be useful) |
* Test function to check if object has been initialized | ||
* | ||
*/ | ||
inline bool isSet(void) { return m_set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: probably don't need void
in the parameter list
One use case is in this PR where I carried a local copy over. We can now do this in a compact way whereas the current code is much uglier -- and exposes a Suggestions for finer tuning welcome. What is there now is so far good enough for me. |
Okay -- LGTM! |
Thanks. @dcdillon and I went back and forth on this. We both really wanted Maybe it can still be done -- suggestions welcome. We now have a few units describing what this should be good for, and one test use over in [RcppGSL] -- and those may help provide a framework for something better. But for now I'd say let's put this one too. |
Ok, being stubborn helps sometimes. We had another crack at this and @dcdillon spotted a really bad |
with a big thanks to Dan
Nullable object (closes #363)
This (simple) PR has been tested in pending code that will may go into mvabund in a few days. (I may use a copy there to not have to rely on the very newest Rcpp there.) But as the feature is generally useful (and I also already spotted use cases for it in RcppDE).
The basic need was described in #363, and we had a lively discussion there. @dcdillon and went back and forth over some design with a templated class but this doesn't quite work: the is circular as we need a
NULL
protection layer around our proxy objects. As soon as we template with them, access whenNULL
leads to an instantiation which ... throws as before. Similarly, I got nowhere with thesafe_bool_idiom
approach.So what is here works, but (as always) could be improved if someone is so inclined. I added a few tests to describe how it is used.