adding properties with mixins
Frank Benoit (keinfarbton)
benoit at tionex.removethispart.de
Fri Nov 10 05:20:17 PST 2006
Actually there is no direct possibility to do this. But it is possible
in two steps:
template Prop( T, alias value, T msk, int shift ){
public T opCall(){
return (( value & msk ) >> shift );
}
public void opCall( T aValue){
value = ( value & ~msk ) | (( aValue << shift ) & msk );
}
}
struct S{
private int priv_data;
private mixin Prop!( int, priv_data, 0x07, 0 ) a_;
public alias a_.opCall a;
private mixin Prop!( int, priv_data, 0x018, 3 ) b_;
public alias b_.opCall b;
}
void main(){
S s;
s.a = 3;
int v = s.a;
s.b = 2;
}
What I want, is to ask for a possibility to make the
instantiating-aliasing step in one step, without the useless mixin name
(a_,b_). Is that possible, or can we add a language feature to make that
possible?
More information about the Digitalmars-d
mailing list