From be9ad6a311a53e9ab8d2a8b69777b73d33b279c3 Mon Sep 17 00:00:00 2001 From: "H. S. Teoh" Date: Wed, 9 Aug 2017 17:03:47 -0700 Subject: [PATCH 1/2] Fix issue 17661: isInputRange should work with .front that returns reference to parameter. --- std/range/primitives.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/range/primitives.d b/std/range/primitives.d index 99064ba73ec..5587e1578bb 100644 --- a/std/range/primitives.d +++ b/std/range/primitives.d @@ -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)); From 4501f5520a65936e1a180d0b37f389d5578fd7af Mon Sep 17 00:00:00 2001 From: "H. S. Teoh" Date: Wed, 9 Aug 2017 17:16:22 -0700 Subject: [PATCH 2/2] Add unittest. --- std/range/primitives.d | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/std/range/primitives.d b/std/range/primitives.d index 5587e1578bb..3dbde44900a 100644 --- a/std/range/primitives.d +++ b/std/range/primitives.d @@ -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)