Conversation
|
Uh oh, it seems i need to replace that uint index with size_t... |
…ement std.range.interfaces.InputRange without having to call inputRangeObject().
4578418 to
ee4778e
Compare
|
Now seems to work also in 64bit. |
|
@dukc: mind the test failures: Also you might want to consider to use the CodeCov extension (or click on the link, or run the coverage locally) as |
| static assert(0, | ||
| "Fiber front is rvalue and thus cannot be moved when it defines a postblit."); | ||
| } | ||
| } |
There was a problem hiding this comment.
How is this different to the generic moveFront implementation?
static if (is(typeof(&r.moveFront)))
{
return r.moveFront();
}
else static if (!hasElaborateCopyConstructor!(ElementType!R))
{
return r.front;
}
else static if (is(typeof(&(r.front())) == ElementType!R*))
{
import std.algorithm.mutation : move;
return move(r.front);
}
else
{
static assert(0,
"Cannot move front of a range with a postblit and an rvalue front.");
}There was a problem hiding this comment.
Except for the message, no difference. I tried to call it, but the first static if caused infinite recursion.
There was a problem hiding this comment.
Works well for me:
There was a problem hiding this comment.
First off, we are talking about std.concurrency.Generator, not about std.range.generate. But that code would work with Generator too, in DPaste.
The reason it does not work in Generator: Look the first static if block in moveFront implementation you just posted. MoveFront(generator) calls generator.moveFront if it can find one -the very function I'm defining!
| return broken; | ||
| } | ||
|
|
||
| final int opApply(scope int delegate(size_t, T) loopBody) |
There was a problem hiding this comment.
Hmm if we have to add opApply to everything that is an InputRange the range concept of "building block" would have somehow failed. Do you know about enumerate and why doesn't it work for you?
There was a problem hiding this comment.
I did not think about it. But wouldn't that plant a land mine for maintenance? If somebody adds an opApply implementation using foreach to enumerate(), it would regress Generators opApply because it would recurse infinitely then.
There was a problem hiding this comment.
What we could add to avoid code duplication for cases like this, is a template mixin version of opApply() and moveFront().
Edit: Or a generic range template which guarantees in it's spec to forward only primitives and nothing else.
There was a problem hiding this comment.
If somebody adds an opApply implementation using foreach to enumerate(), it would regress Generators opApply because it would recurse infinitely then.
I am sorry, but I can't follow. How would sth. like this half-pseudo code end in an infinite recursion?
struct Enumerate(R)
{
R r;
int opApply(scope int delegate(size_t, ElementType!R) dg)
{
int err;
auto r2 = r.save;
for (size_t i; !r2.empty; r2.popFront(), i++)
{
err = dg(i, r2.front);
if (err) return err;
}
return 0;
}
}
myGenerator.enumerate.array;There was a problem hiding this comment.
See also, e.g. https://dpaste.dzfl.pl/57536541877a
There was a problem hiding this comment.
That code won't. But if it's done like (untested, may have errors):
int opApply(scope int delegate(size_t, ElementType!R) dg)
{
int err;
static if(__traits(compiles, foreach(i,e;r){})) foreach (i, e; r.save)
{
err = dg(i, e);
if (err) return err;
} else for (size_t i; !r2.empty; r2.popFront(), i++)
{
auto r2 = r.save;
err = dg(i, r2.front);
if (err) return err;
}
return 0;
}
That, I think, will, because the foreach inside calls the very indexed opApply of R what's using the Enumerate in it's implementation.
std/concurrency.d
Outdated
| * } | ||
| * --- | ||
| */ | ||
| import std.range.interfaces : InputRange; |
There was a problem hiding this comment.
goes at the top of the file
There was a problem hiding this comment.
Doesn't: there was one already! I removed mine altogether.
EDIT: I read that import wrong. Went messy so i squashed.
Removed another useless import. One import wasn't reduntant after all...
7636a43 to
1f926a1
Compare
|
I have no idea what those Linux failures are about... Does somebody have ideas? EDIT: and now it claims all have passed, even when I did no change!? |
-> http://forum.dlang.org/post/bqgywgewtblzpeynrnxu@forum.dlang.org You can click on "Deprecate" for specific builds, but the auto-tester will also perodically iterate through the entire queue and retest your PR ;-) |
b1afc87 to
eddeda6
Compare
eddeda6 to
49bd11b
Compare
|
@wilzbach @JackStouffer Otherwise, ready for further discussion. |
Yeah I have observed this a couple of times already since the S3 outage this week. Don't worry about it. |
|
@wilzbach I have answered your concerns of the code 5 days ago, let's continue discussion? |
|
@dukc people get around to PRs when they can Seb is currently off the grid and probably will be for the rest of the week. |
|
Ok. Just wanted to make sure this wasn't forgotten. |
|
This got too old so i close. I will probably reboot it. |
|
link to new pr: #5309 |
Since std.concurrency.Generator is a class already, I made it to implement std.range.interfaces.InputRange without having to call inputRangeObject().