-
Notifications
You must be signed in to change notification settings - Fork 46
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
refactor traits to conventional enable_if_ prefix #72
Conversation
Thanks, this is much cleaner overall 👍 Two cases that seems to be failing with this code
And the other is I handled the latter with 16202d1, unfortunately we can't just rely on the Not sure what the best approach is for the first issue. |
Looks like I can't template <typename T, typename R = void>
using enable_if_std_string = enable_if_t<std::is_same<typename std::decay<T>::type, std::string>::value, R>; |
This prevents construction of a reference rather than real object
@romainfrancois an enable_if typedef is not an ideal place to decay types since it leads to less transparent traits and potential unnecessary temporaries. I'm planning to fix this with an |
I am curious why |
Sorry, my example should have been In any case I think I have worked around all the issues. @bkietz if you could review my changes in 7422fa and 17dc1fe that would be great. Feel free to make and commit any changes to what I did that still allow the tests to pass if you know of cleaner ways to handle it. |
@jimhester those look good to me. As a general comment, however: it seems questionable to me that we accept references and const/volatile qualifiers in the template argument to Related to 16202d1 should this be applied to |
We need to return the regular The reason the Perhaps we should instead do as you suggest and remove the types and references when generating the wrapping code. My main hesitation is we would have to do this using R code and I was not certain if we could do it reliable. But maybe a regex as simple as |
I'd work around this by providing [[cpp11::register]] std::string leftpad(const std::string& s, char pad, size_t length) {
return s + "TODO";
} I'd like to generate: std::string leftpad(const std::string& s, char pad, size_t length);
extern "C" SEXP _acceleratedformatutils_leftpad(SEXP s, SEXP pad, SEXP length) {
BEGIN_CPP11
return cpp11::as_sexp(leftpad(
cpp11::unmove(cpp11::as_cpp<cpp11::decay_t<const std::string&>>(s)),
cpp11::unmove(cpp11::as_cpp<cpp11::decay_t<char>>(pad)),
cpp11::unmove(cpp11::as_cpp<cpp11::decay_t<size_t>>(length))
));
END_CPP11
} As a bonus, I think we wouldn't need |
That is a good idea 👍, I like it. |
I will merge this for now I think, and I can work on that proposal in a separate PR. |
Also cleaned up some reliance in the traits on implicit conversions, which can be painful to debug