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

arbitrary number of arguments in RCPP_RETURN_VECTOR #38

Closed
eantonya opened this issue Nov 8, 2013 · 8 comments · Fixed by #537
Closed

arbitrary number of arguments in RCPP_RETURN_VECTOR #38

eantonya opened this issue Nov 8, 2013 · 8 comments · Fixed by #537

Comments

@eantonya
Copy link

eantonya commented Nov 8, 2013

Currently it only take one-argument functions - add a variadic extension, to be able to use functions with multiple arguments in addition to just the SEXP.

@romainfrancois
Copy link
Contributor

Can you share some examples ? Not a big fan of variadics in a pre C++11 world. They bring type safety issues, ...

@eantonya
Copy link
Author

E.g. writing a subset function that has two arguments - a Vector<> and an integer vector that will select appropriate elements from the Vector.

@romainfrancois
Copy link
Contributor

Not sure it is worth generalizing it, we are going to end up with multiple macros like RCPP_RETURN_VECTOR_1, RCPP_RETURN_VECTOR_2, ... and we (at least until july) have already lots of macro code bloat noise in Rcpp.

@eantonya
Copy link
Author

Perhaps I'm missing something about the compiler restrictions you have, but
this type of code works fine for me:

#define dispatch(FUN, SEXP,
...)
switch (TYPEOF(SEXP))
{
case
INTSXP:
return FUN< Vector >(Vector(SEXP),
##VA_ARGS);
...

On Fri, Nov 15, 2013 at 12:57 AM, Romain François
notifications@github.comwrote:

Not sure it is worth generalizing it, we are going to end up with multiple
macros like RCPP_RETURN_VECTOR_1, RCPP_RETURN_VECTOR_2, ... and we (at
least until july) have already lots of macro code bloat noise in Rcpp.


Reply to this email directly or view it on GitHubhttps://github.com//issues/38#issuecomment-28550815
.

@romainfrancois
Copy link
Contributor

variadic macros have only been integrated into the standard in C++11. So this is not standard C++, so we can't have this in Rcpp.

it could go into Rcpp11 which assumes C++11.

I'm closing this as it is not going to happen. sorry.

@artemklevtsov
Copy link
Contributor

artemklevtsov commented Aug 7, 2016

Now we can implement this with the conditional define (with RCPP_USING_CXX11).

@eddelbuettel
Copy link
Member

Maybe. Something small and local would be a good test.

I would not want to have to TWICE the rev.dep'ing but it still works (maybe without the feature) in C++98 and adds a new chiefly at interface / edge feature that nothing else in Rcpp itself depends upon, we could.

Alternatively, maybe an add-on package could be used. If you do it in headers all it "costs" users is another LinkingTo:. Might be cleaner. Either way -- want to do a pull request?

@artemklevtsov
Copy link
Contributor

artemklevtsov commented Aug 7, 2016

We need a minimal changes (example here) so existing code will work.
Revdeps seems is no problem:

Is better define additional macro (RCPP_RETURN_VECTOR2?) or conditional redefine an existing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants