Skip to content

Commit

Permalink
Merge pull request #5688 from quickfur/issue17661
Browse files Browse the repository at this point in the history
Issue 17661: isInputRange should accept .front that returns reference to range
merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Aug 14, 2017
2 parents 61820b7 + 4501f55 commit 6b460ab
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion std/range/primitives.d
Expand Up @@ -164,7 +164,7 @@ Returns:
enum bool isInputRange(R) =
is(typeof(R.init) == R)
&& is(ReturnType!((R r) => r.empty) == bool)
&& is(typeof((R r) => r.front))
&& is(typeof((return ref R r) => r.front))
&& !is(ReturnType!((R r) => r.front) == void)
&& is(typeof((R r) => r.popFront));

Expand Down Expand Up @@ -220,6 +220,31 @@ enum bool isInputRange(R) =
static assert(!isInputRange!VoidFront);
}

@safe unittest
{
import std.algorithm.comparison : equal;

static struct R
{
static struct Front
{
R* impl;
@property int value() { return impl._front; }
alias value this;
}

int _front;

@property bool empty() { return _front >= 3; }
@property auto front() { return Front(&this); }
void popFront() { _front++; }
}
R r;

static assert(isInputRange!R);
assert(r.equal([ 0, 1, 2 ]));
}

/+
puts the whole raw element $(D e) into $(D r). doPut will not attempt to
iterate, slice or transcode $(D e) in any way shape or form. It will $(B only)
Expand Down

0 comments on commit 6b460ab

Please sign in to comment.