Peter Modzelewski:
> You can download the slides from:
> http://team0xf.com/conference/gamedev.pdf

The serialization example, page 21 of the slides, is interesting. The 
API/syntax they use doesn't look too much readable, but such functionality is 
probably quite useful in certain kinds of D programs. So D may enjoy a little 
more handy ways to manage its reflective information. Avoiding most of such 
serialization hack.


The following code is cleaned/improved from the OMG:
http://team0xf.com:8080/omg/file/aca17fefefc1/core/Algebra.d
But does it work? Strings turns up being "summable", but if you actually add 
them you get an "Array operations not implemented" error:

import std.stdio: writefln;

template isRingType(T) {
    const bool isRingType = is(typeof(T.init + T.init)) &&
                            is(typeof(T.init - T.init)) &&
                            is(typeof(T.init * T.init));
}

template isFieldType(T) {
    const bool isFieldType = isRingType!(T) && is(typeof(T.init / T.init));
}

template isSummable(T) {
    const bool isSummable = is(typeof(T.init + T.init));
}

void main() {
    writefln( isSummable!(string) );
    writefln( isRingType!(string) );
    //writefln( string.init + string.init ); // test.d(20): Error: Array 
operations not implemented
}

Bye,
bearophile

Reply via email to