www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - adding properties with mixins

reply "Frank Benoit (keinfarbton)" <benoit tionex.removethispart.de> writes:
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?
Nov 10 2006
parent Walter Bright <newshound digitalmars.com> writes:
It may be possible, but it's kinda hard to fit in at the moment.
Nov 10 2006