Skip to content

Instantly share code, notes, and snippets.

@rikkimax
Last active September 18, 2018 00:41
Show Gist options
  • Save rikkimax/e7dd01294c9ad4910fbd7a7e96cf4cc9 to your computer and use it in GitHub Desktop.
Save rikkimax/e7dd01294c9ad4910fbd7a7e96cf4cc9 to your computer and use it in GitHub Desktop.
struct MyRange<Type> {
@property {
Type delegate() front;
bool delegate() empty;
}
void delegate() popFront;
@implicit static auto opCall(T)(T from) {
MyRange!(Type: T.Type) ret;
ret.front = &from.front;
ret.empty = &from.empty;
ret.popFront = &from.popFront;
return ret;
}
}
auto:MyRange something(T)(T from) if (is(T : MyRange)) {
return MyRange(from);
}
signature MyRange<Type> {
@property {
Type front();
bool empty();
}
void popFront();
}
// is Signature type
MyRange something(T)(T from) if (is(T : MyRange)) {
// T is of type MyRange, existing syntax
return from;
}
// is Signature initialized type
MyRange something2(T)(T from) if (is(T : MyRange!(Type: int))) {
return from;
}
// can type become Signature?
MyRange something3(T:MyRange)(T from) {
// new
return from;
}
// can type become a Signature?
MyRange something4(T:MyRange!(Type: int))(T from) {
// new
return from;
}
// make Signature from type
MyRange something5(T)(T:MyRange from) {
// new, erase T for mangling + emitting purposes
// replace with any parameters on MyRange side
return from;
}
// make a Signature from type
MyRange something6(T)(T:MyRange!(Type: int) from) {
// new, erase T for mangling + emitting purposes
return from;
}
struct Implementation {
alias Type = int;
@property {
Type front() { return Type.init; }
bool empty() { return true; }
}
void popFront() {}
}
static assert(is(MyRange(Implementation.init) == MyRange!(Type: int)));
Copy link

ghost commented Sep 18, 2018

i only see the IRC notification now. So you plan to use angle brackets finally.

Copy link

ghost commented Sep 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment