digitalmars.D.learn - Templates with multiple enums are void
- Jonathan M Davis (27/27) Aug 27 2010 This prints out void:
- Don (5/39) Aug 27 2010 You're wrong about that.
- Simen kjaeraas (6/30) Aug 27 2010 Actually, according to TDPL, that is correct. "A template using the
- Jonathan M Davis (6/12) Aug 27 2010 Ah, that must have been where I ran into it, though I _thought_ that I'd...
- Andrej Mitrovic (4/38) Aug 27 2010 Yeah, I ran into this as well. And I've posted about it on this NG alrea...
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
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
Don <nospam nospam.com> wrote:Jonathan M Davis wrote: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) -- SimenThis 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.
Aug 27 2010
On Friday, August 27, 2010 14:55:12 Simen kjaeraas wrote:Don <nospam nospam.com> wrote: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 DavisYou'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)
Aug 27 2010
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: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) -- SimenThis 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.
Aug 27 2010