Last active
September 18, 2018 00:41
-
-
Save rikkimax/e7dd01294c9ad4910fbd7a7e96cf4cc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); |
Well i knew this already at some point (https://gist.github.com/BBasile/ef7b3f5d0e34bcad1b55e122e30082d7)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i only see the IRC notification now. So you plan to use angle brackets finally.