Yigal Chripun wrote:
grauzone wrote:
Yigal Chripun wrote:
I really wish this was folded into the language by allowing structs
to implement interfaces.
interface Range(T) {
bool empty();
void popFront();
T front();
}
struct MyRange(T) : Range!(T) { ... } // checked by compiler
One problem with this was that arrays wouldn't automagically be ranges
anymore. Right now, "int[] a; a.popFront();" works, because std.array
has a global function popFront. Some old language hack turns
a.popFront into popFront(a).
you're talking about this construct:
int[] arr;
void foo(int[], params) {} => arr.foo(params);
This should not be considered a hack but rather should be a feature
extended for all types. see extension methods in C#.
I'd rather have some sort of open types, which are the clean version of
this hack.
I also think that arrays (containers) must be distinct from
slices/ranges (views).