arbitrary number of arguments in RCPP_RETURN_VECTOR #38

Closed
eantonya opened this Issue Nov 8, 2013 · 8 comments

Projects

None yet

4 participants

@eantonya
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
Contributor

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

@eantonya

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
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

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/RcppCore/Rcpp/issues/38#issuecomment-28550815
.

@romainfrancois
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
Contributor
artemklevtsov commented Aug 7, 2016 edited

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

@eddelbuettel
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
Contributor
artemklevtsov commented Aug 7, 2016 edited

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