Skip to content

Commit

Permalink
Use isQualifierConvertible in isInputRange!(R, E)
Browse files Browse the repository at this point in the history
This replaces the bespoke type comparison that was previously used. All
conversions allowed by the previous version are still allowed after this
change.
  • Loading branch information
pbackus committed Oct 27, 2023
1 parent 4eb622e commit 977e6ad
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions std/range/primitives.d
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,24 @@ See_Also:
Params:
R = type to be tested
E = the type of the elements of the range if not `void`
E = if present, the elements of the range must be
$(DDSUBLINK spec/const3, implicit_qualifier_conversions, qualifier-convertible)
to this type
Returns:
`true` if R is an input range (possibly with element type `E`), `false` if not
*/
enum bool isInputRange(R, E = void) =
enum bool isInputRange(R) =
is(typeof(R.init) == R)
&& is(typeof((R r) { return r.empty; } (R.init)) == bool)
&& (is(typeof((return ref R r) => r.front)) || is(typeof(ref (return ref R r) => r.front)))
&& !is(typeof((R r) { return r.front; } (R.init)) == void)
&& is(typeof((R r) => r.popFront))
&& (is(E == void) ||
is(ElementType!R == E) ||
is(const(ElementType!R) == E) ||
(is(const(ElementType!R) == immutable E) && is(const(E) == E)));
&& is(typeof((R r) => r.popFront));

/// ditto
enum bool isInputRange(R, E) =
.isInputRange!R && isQualifierConvertible!(ElementType!R, E);

///
@safe unittest
{
Expand Down

0 comments on commit 977e6ad

Please sign in to comment.