Templates with multiple enums are void

Simen kjaeraas simen.kjaras at gmail.com
Fri Aug 27 14:55:12 PDT 2010


Don <nospam at nospam.com> wrote:

> 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.

Actually, according to TDPL, that is correct. "A template using the
eponymous trick may define other names inside, but those are simply
inaccessible from the outside." (page 281)

-- 
Simen


More information about the Digitalmars-d-learn mailing list