Troublemaker dmd 2.061 - Templates?
nazriel
spam at dzfl.pl
Mon Jan 7 07:59:10 PST 2013
On Saturday, 5 January 2013 at 18:45:26 UTC, David wrote:
> 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.
Report a bug and mark it as regression if it is one.
More information about the Digitalmars-d-learn
mailing list