www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Templates with multiple enums are void

reply Jonathan M Davis <jmdavisprog gmail.com> writes:
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? 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.

- Jonathan M Davis
Aug 27 2010
next sibling parent reply Don <nospam nospam.com> writes:
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.
Aug 27 2010
parent Andrej Mitrovic <andrej.mitrovich test.com> writes:
Yeah, I ran into this as well. And I've posted about it on this NG already.


I have made this bug report some time ago:

http://d.puremagic.com/issues/show_bug.cgi?id=4675



Simen kjaeraas Wrote:

 Don <nospam 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

Aug 27 2010
prev sibling next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Don <nospam 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
Aug 27 2010
prev sibling parent Jonathan M Davis <jmdavisprog gmail.com> writes:
On Friday, August 27, 2010 14:55:12 Simen kjaeraas wrote:
 Don <nospam nospam.com> wrote:
 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)

Ah, that must have been where I ran into it, though I _thought_ that I'd done it before. I guess not. I would have read it in TDPL though, since I read the whole thing. That _does_ mean that it should be possible eventually, but it obviously isn't right now. At least now I know why I thought that you could do it. - Jonathan M Davis
Aug 27 2010