On 2013-11-21 00:48, Dicebot wrote:
http://dlang.org/phobos/std_range.html#isInputRange
This is the very point - for simple stuff like Phobos ranges defining
interface types is actually more verbose than simply creating unique
constraints and does not really bring much. It would have been much more
interesting if `std.typecons.wrap` would have accepted structs though.
Currently isInputRange looks like this:
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
(inout int = 0)
{
R r = void; // can define a range object
if (r.empty) {} // can test for empty
r.popFront(); // can invoke popFront()
auto h = r.front; // can get the front of the range
}));
}
void foo (R) (R r) if(isInputRange!(R))
I guess his suggestion would be something like this:
interface InputRange (R)
{
@property bool empty ();
void popFront ();
ElementType!(R) front ();
}
void foo (R) (R r) if(implements!(InputRange!(R)))
Personally I think it's nice to have a concrete type like this.
--
/Jacob Carlborg