Created
August 8, 2013 06:00
-
-
Save psihy/6181856 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
import std.traits; | |
struct Signed {} | |
struct Unsigned {} | |
struct Wrapper(V, T) { | |
private V value; | |
private T tag; | |
alias value this; | |
int opEquals(Wrapper o) const { | |
return o.value == value; | |
} | |
} | |
auto wrap(V)(V v) if (isSigned!V) { | |
return Wrapper!(V, Signed)(v); | |
} | |
auto wrap(V)(V v) if (isUnsigned!V) { | |
return Wrapper!(V, Unsigned)(v); | |
} | |
void main() { | |
assert(wrap(42) == wrap(42)); | |
assert(wrap(42) == wrap(42u)); // compile error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment