Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] optional passing by reference #82

Open
dselivanov opened this issue Dec 26, 2019 · 1 comment
Open

[feature request] optional passing by reference #82

dselivanov opened this issue Dec 26, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@dselivanov
Copy link
Contributor

In general it is not desirable to change arguments in-place, but in some cases it is useful (when you now what you do). So mb it is possible to add by_reference = FALSE argument to type annotations to control how arguments are passed? and if by_reference then function signature might be F(arma::mat &x) instead of F(arma::mat x)

@dirkschumacher
Copy link
Owner

Sounds like a good idea to use the type hints to control that. Currently a const ref is used by default unless the code mutates the parameter, then it is changed to a copy.

library(armacmp)
translate(function(X, Y) {
  X <- X + 1
  return(X + Y)
}, "test")
#> R function
#> 
#> function (X, Y) 
#> {
#>     X <- X + 1
#>     return(X + Y)
#> }
#> 
#> C++ function translation
#> 
#> arma::mat test(arma::mat X, const arma::mat& Y)
#> {
#> X = X + 1.0;
#> return X + Y;
#> }
#> 

Created on 2019-12-26 by the reprex package (v0.3.0)

@dirkschumacher dirkschumacher added the enhancement New feature or request label Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants