Templates with multiple enums are void

Don nospam at nospam.com
Fri Aug 27 13:41:46 PDT 2010


Jonathan M Davis wrote:
> This prints out void:
> 
> import std.stdio;
> 
> template isX(T)
> {
>     enum val = true;
>     enum isX = val;
> }
> 
> void main()
> {
>     writeln(typeof(isX!(int)).stringof);
> }
> 
> 
> If you change it to
>  
> template isX(T)
> {
>     enum val = true;
>     enum isX = true;
> }
> 
> 
> it still prints out void. If you get rid of val, it finally prints bool. However, 
> as I understood it, you should be able to declare multiple enums within the same 
> template and get this to work as long as you just have the one with the same 
> name as the template. Am I wrong about that? 

You're wrong about that.

Or is this a bug?
> 
> It's certainly limiting if you can't declare multiple enums. What I'd like to be 
> able to do is create multiple enums and then && them together to create isX, 
> thereby nicely breaking up the condition into more manageable pieces. But it 
> doesn't appear to work at the moment.

It's probably the most duplicated enhancement request in the history of 
D. It must have been suggested a dozen times.


More information about the Digitalmars-d-learn mailing list