declarations as template parameters

Meta via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 31 14:14:41 PDT 2015


On Sunday, 30 August 2015 at 18:43:32 UTC, Adam D. Ruppe wrote:
> On Sunday, 30 August 2015 at 16:31:17 UTC, Daniel N wrote:
>> I guess it could be possible to solve using UDA:s instead... 
>> maybe I'll try that next, just checking if I'm the only one 
>> dreaming about "declarations as template parameters".
>
> What I would love would be being able to pass an anonymous 
> struct to a template. Then you can reflect over it to get 
> declarations and group them too.
>
> (Actually, I'd love to be able to use anonymous structs 
> anywhere a typename is expected. Then you could do:
>
> struct { int a; } foo; // declare a variable named foo as type 
> struct { int a; }
>
> but that might break the parser.)

This would go great with Algebraic.

alias List(T) = Algebraic!(
     struct Cons { T data; This* next; },
     struct Nil  {},
);


More information about the Digitalmars-d mailing list