-
-
Notifications
You must be signed in to change notification settings - Fork 739
Add std.functional.acceptRVals #3937
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
Conversation
fdaba47
to
85de341
Compare
Nitpick: rvalue is one word no? So shouldn't this be |
"rvalue" is not an English word; if it was there would be a vowel or two attached to the "r" giving some hint as to how to pronounce it. It's really an abbreviation for something like "right-hand value". (Of course, I can still change the capitalization if that's what people really want.) |
I included a Anyone know why? I thought all I had to do was stick |
assert(x == 0); | ||
|
||
// The wrapped function can be anonymous: | ||
mixin acceptRVals!("mul", function(ref const(int) a, ref const(int) b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability's sake, could you please break these up into multiple ddoc-ed unit tests.
85de341
to
f277625
Compare
Sure it is, it's just jargon. |
You asked for my opinion; I gave it. This is a silly thing to argue about. If there is consensus that I should change it, I will do so. |
fd07a67
to
18688f0
Compare
The |
67ce32a
to
633488a
Compare
This doesn't look well. Part of the problem is it's an all-or-nothing proposition for all parameters. Not to mention it's awkward to use. A possibility would be to add this: ref T ignoreLval(uint param, T)(T value)
{
static T lvalue;
move(value, lvalue);
return lvalue;
} Then people who want to call |
That's kind of the point. People expect passing rvalues by reference to "just work" as long as the reference isn't being escaped. I exempted |
Oops. I accidentally hit close; ignore that. |
I really don't think anyone wants that; it has the same poor scaling as just making temporary variables: it requires additional code for every single function call with rvalues, rather than just modifying the declaration. Also, it depends on TLS which could be substantially slower than my solution unless the optimizer is smarter than I think. One of the reasons that people (i.e. Manu) want to use |
That struck me as unsafe from the moment I saw it, and I finally figured out why: in a (directly or indirectly) recursive function, This could happen even if the Also, |
ping @TurkeyMan Could you please take a quick look at this, and let me know if it is at all useful to you? I made it because of the rval->ref const(T) thread you started a couple of days ago, but you never replied to me or anyone else in that thread. No one else seems very enthusiastic about this PR so far, so if you aren't interested then I'll just close it. |
} | ||
|
||
if ((p + 1) < names.length) | ||
append(", "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(p>0)append(", ");
at the start of the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@d-random-contributor Thanks.
I'm not sure why I didn't do that in the first place; I've used that idiom before.
…epts rvalue refs.
633488a
to
9c56d16
Compare
I'll just close this now since no one else seems particularly interested. |
@TurkeyMan
std.functional.acceptRVals
is amixin template
that generates a function wrapper that will accept rvalue arguments, even forref
parameters.I've attempted to properly handle all the weird stuff like
return ref
,ref
return type, function attributes, class methods, variadic functions, etc.The main thing it doesn't do, is automate wrapping a template function from the outside. You either have to wrap it from the inside, or wrap a specific instantiation.
TODO: I should add more unit tests, but I figure this is enough for me to request feedback.