Description
The XPtr
class wraps somewhat narrowly around R's own external pointers. The class actually has three fields: the pointer, a tag and a protect field. WRE, Section 5.13.1 has an example of setting the tag (of type SEXP
, so can be anything) to a string. Searching the CRAN org here at GitHub (with its effective CRAN mirror) shows a few packages using this ... for various purposes, sometimes even second payloads.
Now, because the external pointer is effectively a naked C pointer, it would be useful to also offer some type checking. Following some initial discussion (thanks, @ihnorton) I am currently prototyping use with the tiledb
package. But as this is generally useful we should support it here in time (maybe the July release, maybe next January).
Among the obvious missing features are
- a tag getter in the
XPtr
class - an alternate
XPtr
creation helper setting pointer and tag - and likely more
Following some quick discussion with @Enchufa2 there is also an idea to automate this further via typeid()
and std::type_info()
(though that may not work for user-defined classes, where I also ran into some potholes on initial probing with C++17-ish features).
In any event, this seems like a fruitful avenue to venture down so opening this ticket to collect more ideas.