MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / xptr_1

Function xptr_1

inst/tinytest/cpp/XPtr.cpp:26–41  ·  view source on GitHub ↗

[[Rcpp::export]]

Source from the content-addressed store, hash-verified

24
25// [[Rcpp::export]]
26XPtr< std::vector<int> > xptr_1(){
27 /* creating a pointer to a vector<int> */
28 std::vector<int>* v = new std::vector<int> ;
29 v->push_back( 1 ) ;
30 v->push_back( 2 ) ;
31
32 /* wrap the pointer as an external pointer */
33 /* this automatically protected the external pointer from R garbage
34 collection until p goes out of scope. */
35 XPtr< std::vector<int> > p(v) ;
36
37 /* return it back to R, since p goes out of scope after the return
38 the external pointer is no more protected by p, but it gets
39 protected by being on the R side */
40 return( p ) ;
41}
42
43// [[Rcpp::export]]
44int xptr_2( XPtr< std::vector<int> > p){

Callers

nothing calls this directly

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected