Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 27, 2010 Templates with multiple enums are void | ||||
---|---|---|---|---|
| ||||
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 |
August 27, 2010 Re: Templates with multiple enums are void | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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. |
August 27, 2010 Re: Templates with multiple enums are void | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don | 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 |
August 27, 2010 Re: Templates with multiple enums are void | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen kjaeraas | 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
|
August 27, 2010 Re: Templates with multiple enums are void | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen kjaeraas | 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 |
Copyright © 1999-2021 by the D Language Foundation