Retain struct when using alias this and passing using the alias..?
simendsjo
simendsjo at gmail.com
Sun Jun 24 06:16:51 PDT 2012
import std.exception;
import std.traits;
struct Ranged(T, T min, T max) {
T _value = min;
typeof(this) opAssign(V : T)(V value) {
enforce(value >= min);
enforce(value <= max);
_value = value;
return this;
}
alias _value this;
}
void f(int i) {
i = 1000;
}
void g(T)(T i) if(isIntegral!T){
i = 1000;
}
void main() {
Ranged!(int, 10, 20) v;
v = 10; // ok
v = 20; // ok
f(v); // auch
g(v); // ok, exception
}
Is there a way to ensure the struct is used in f() without using templates
as in g()?
More information about the Digitalmars-d-learn
mailing list