On 03/12/2013 05:16 PM, Andrei Alexandrescu wrote:
On 3/12/13 11:47 AM, Steven Schveighoffer wrote:
...
Wouldn't this also be valid?

if(!R.init.empty)

Essentially, you can evaluate R.init.empty at compile time AND it's
false on an uninitialized range. How can a correctly written
non-infinite range pass that?

That would make forwarding much easier, as the 'dumb' implementation
still would result in an infinite range.

Crossed my mind a few times that fresh non-infinite ranges should be
empty. But there's no explicit requirement stating that, and I think
e.g. one may define a k-elements buffer backed by in-situ storage.

Andrei

std.algorithm.joiner assumes that default-initialized separator ranges are empty.

import std.algorithm, std.array, std.range;

struct NonEmptyRange{
        int[] a = [0,8];
        @property int front(){ return a.front; }
        @property bool empty(){ return a.empty; }
        void popFront(){ a.popFront(); }
        @property NonEmptyRange save(){ return NonEmptyRange(a.save); }
}

void main(){

assert(equal([[1,2,3],[1,2,3]].joiner(NonEmptyRange()),[1,2,3,0,8,1,2,3])); // fail
}

I'd report it, but the bug tracker is down.

Reply via email to