On Wednesday, 6 June 2012 at 20:52:14 UTC, bearophile wrote:
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.
Well if it was only 1-2 value I wouldn't probably have bothered.
However when there are several flags enums and values that are
calculated based on eachother and used together; I wouldn't want
to write enums manually for each type.
Seems I'm being thrown now into the deep end of templates and
constraints and traits and trying to fully understand it enough
to use it all. What an exciting time to be alive :)