On Thursday, November 15, 2012 13:17:12 jerro wrote: > > std.array.array will never work with ranges with a transient > > front unless it > > somehow knew when it was and wasn't appropriate to dup, which > > it's not going > > to know purely by looking at the type of front. The creator of > > the range would > > have to tell them somehow. And even then, it wouldn't work > > beyond the built-in > > types, because there's no generic way to dup stuff. > > Daniel was actually talking about std.byLine.map!"a.dup", which > is not a transient range, but would be considered transient if we > did what Andrei suggests.
Well, there's no way around that as far as I can see. Even if all ranges had to be explicitly marked as transient or not, map would be in a bind here, because it knows nothing about what the function it was given is doing, so it has no way of knowing how it affects transience. At minimum, it would be forced to mark itself as transient if the original range was (even if the function used idup), or it would _always_ be forced to mark it as transient (I'm not sure which). The only way out would be if there were a way to tell map explicitly to mark the resultant range as having a non-transient front. By using type deduction like Andrei is suggesting, then we can at least deduce that map!"a.idup" has a non-transient front, but the only way that we'd know that map!"a.dup" was non-transient was if map were told somehow, and it defined an enum that the hasTransientFront trait could examine (i.e. we're back in the boat we'd be in if all ranges had to declare whether they were transient or not). So, as long as we can have transient fronts, map!"a.dup" is screwed, which may or may not be a problem. It's arguably a lot like how we keep having to explain why functions don't work with narrow strings because of how narrow strings aren't random-access, don't have length, etc. And that's definitely annoying, but we can't really fix it. It's looking like this comes down to either banning ranges with transient fronts entirely (and changing how ByLine and ByChunk work), or we're going to have to deal with quirks like array(map!"a.dup"(file.byLine())) not working whereas array(map!"a.idup"(file.byLine())) does work. - Jonathan M Davis