November 10, 2006 adding properties with mixins | ||||
|---|---|---|---|---|
| ||||
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?
| ||||
November 10, 2006 Re: adding properties with mixins | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit (keinfarbton) | It may be possible, but it's kinda hard to fit in at the moment. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply