Troublemaker dmd 2.061 - Templates?

David d at dav1d.de
Sat Jan 5 10:45:25 PST 2013


LOL
mixin template get_packets_mixin(alias Module) {
    template get_packets() {
        alias NoDuplicates!(get_packets_impl!(get_members!())) get_packets;
    }

    template get_members() {
        alias TypeTuple!(__traits(allMembers, Module)) get_members;
    }

    private template get_packets_impl(T...) {
        static if(__traits(compiles, mixin(T[0]).id)) {
//             pragma(msg, PacketTuple!(mixin(T[0]), mixin(T[0]).id));
//             pragma(msg, get_packets_impl!(T[1..$]));
            alias TypeTuple!(PacketTuple!(mixin(T[0]), mixin(T[0]).id),
get_packets_impl!(T[1..$])) get_packets_impl;
        } else {
//             pragma(msg, get_packets_impl!(T[1..$])); // <----------
            alias TypeTuple!(get_packets_impl!(T[1..$])) get_packets_impl;
        }
    }

    private template get_packets_impl() {
        alias TypeTuple!() get_packets_impl;
    }

    template PacketTuple(T, ubyte b) {
        alias T cls;
        alias b id;
    }

    auto parse_packet(ubyte id)(Stream s) {
        alias staticIndexOf!(id, staticMap!(extract_id, get_packets!()))
id_index;
        static if(id_index < 0) {
            static assert(false, "Invalid packet with id: " ~
toStringNow!id);
        } else {
            return get_packets!()[id_index].cls.recv(s);
        }
    }

    pragma(msg, get_packets_impl!(__traits(allMembers, Module)));
}

With this pragma: "pragma(msg, get_packets_impl!(T[1..$]));"
outcommented, I get _error_, but if I let it in, everything compiles.

I have no idea if I should laugh or cry.


More information about the Digitalmars-d-learn mailing list