[[Rcpp::export]]
| 24 | |
| 25 | // [[Rcpp::export]] |
| 26 | XPtr< 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]] |
| 44 | int xptr_2( XPtr< std::vector<int> > p){ |