[Rcpp-devel] changing a "const" argument

Romain Francois romain at r-enthusiasts.com
Fri Nov 16 15:06:57 CET 2012


Hmm. Not sure. Something to look for I guess.


The const and non const versions of the operator[] are identical:

inline Proxy operator[]( int i ){ return cache.ref(i) ; }
inline Proxy operator[]( int i ) const { return cache.ref(i) ; }

I'll have a look.

Romain

Le 16/11/12 15:00, Ramon Diaz-Uriarte a écrit :
> Dear All,
>
> I thought something like this would fail (would not compile):
>
>
> // [[Rcpp::export]]
> double changeAVector(const NumericVector a) {
>    a[0] = 3.0;
>    return 44.0;
> }
>
>
>
> But it does compile OK, and it really does modify the argument:
>
> d1 <- c(93, 99); changeAVector(d1); d1
>
>
> Is this expected?
>
>
> Thanks,
>
>
> R.
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com
`- http://bit.ly/SweN1Z : SuperStorm Sandy

blog:            http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible



More information about the Rcpp-devel mailing list