Skip to content

Instantly share code, notes, and snippets.

@psihy
Created August 8, 2013 06:00
Show Gist options
  • Save psihy/6181856 to your computer and use it in GitHub Desktop.
Save psihy/6181856 to your computer and use it in GitHub Desktop.
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