Templated Enums?

bearophile bearophileHUGS at lycos.com
Wed Jun 6 13:52:13 PDT 2012


Johannes Pfau:

> it should be possible to do this:
> ---------------
> template X(T)
> {
>     enum X
>     {
>         bitsPerT = T.sizeof * 8,
>     }
> }

That seems correct, this works:

template Foo(T) {
    enum Foo {
        bitsPerT = T.sizeof * 8,
    }
}
void main() {
     pragma(msg, Foo!int.bitsPerT);
}


So if template Foo(T){enum Foo{}} works, then I think it should 
also work the enum Foo(T){} syntax.

So far I don't think I have had to use templated enums, but if 
other people have such need, than this thread and this post have 
enough material for a little enhancement request.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list