<div dir="ltr">I entirely missed that thread ... sorry. I came across the above examples at:<div><div><br></div><div><a href="http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-April/005680.html">http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-April/005680.html</a></div>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 11, 2013 at 8:38 PM, Gabor Grothendieck <span dir="ltr"><<a href="mailto:ggrothendieck@gmail.com" target="_blank">ggrothendieck@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, Jul 11, 2013 at 8:32 AM, Changi Han <<a href="mailto:changi.han.wen@gmail.com">changi.han.wen@gmail.com</a>> wrote:<br>

> Hello,<br>
><br>
> I think I (superficially) understand the difference between:<br>
><br>
> // [[Rcpp::export]]<br>
> double sum1(Rcpp::NumericMatrix M) {<br>
>     arma::mat A(M.begin(), M.rows(), M.cols(), false);<br>
>     return sum(sum(A));<br>
> }<br>
><br>
><br>
> // [[Rcpp::export]]<br>
> double sum2(arma::mat A) {<br>
>     return sum(sum(A));<br>
> }<br>
><br>
> Partly out of laziness, partly because sum2 is more elegant, and partly to<br>
> avoid namespace pollution, I was wondering if there is a way to "force" a<br>
> "shallow" copy in sum2.<br>
><br>
> If not, then may I submit a low priority feature request. An attribute? Some<br>
> thing like:<br>
><br>
> // [[Rcpp::export]]<br>
> double sum2(arma::mat A) {<br>
>     // [[ Rcpp::shallow ( A ) ]]<br>
>     return sum(sum(A));<br>
> }<br>
><br>
> Or (akin to C++11 generalized attributes)<br>
><br>
> // [[Rcpp::export]] { [[ Rcpp::shallow ( A ) ]] }<br>
> double sum2(arma::mat A) {<br>
>     return sum(sum(A));<br>
> }<br>
><br>
> An alternative is to have an argument in sourceCpp that takes a list/vector<br>
> of objects that are to be shallow or deep copied.<br>
><br>
> For example in sum1, if M is changed within the function before casting to<br>
> the arma::mat, then might be cleaner to add M to a list/vector of objects to<br>
> be deep copied rather than cloning M within sum1: leads to one fewer<br>
> variable name.<br>
><br>
> Just a thought. I can certainly live with the additional step. As always,<br>
> thanks for all the Rcpp goodness.<br>
<br>
</div></div>I had just made a similar suggestion in my post about half an hour ago.<br>
</blockquote></div><br></div>