www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Identify enum

reply Moritz Warning <moritzwarning web.de> writes:
I have a global toString template function that is also used for various 
enums.
If the toString is used for an unknown Type it's supposed to print out
an error message at compile time (static assert).

Now I face the problem that toString is used for some enum I haven't 
modified toString for, but I can't identify the the enums name.
All I get is the base type int, which is pretty useless.

I can search my entire codebase and make a list of all enum types it is 
used for. But that's pretty hard for some big templates engines.

Is there a workaround?
Jul 21 2008
parent reply BCS <ao pathlink.com> writes:
Reply to Moritz,

 I have a global toString template function that is also used for
 various
 enums.
 If the toString is used for an unknown Type it's supposed to print out
 an error message at compile time (static assert).
 Now I face the problem that toString is used for some enum I haven't
 modified toString for, but I can't identify the the enums name.
 All I get is the base type int, which is pretty useless.
 I can search my entire codebase and make a list of all enum types it
 is used for. But that's pretty hard for some big templates engines.
 
 Is there a workaround?
 
A little more info might be useful. As a starting point I'll assume the toString is something like this: char[] toString(T)(T arg)... { static if(is(T == type1)) {something} else static if(is(T type2)) {something} ... else static assert(false,"can't use "~T.stringof); } and that the assert is giving something useless. Is that the case or are you taking a different approach?
Jul 21 2008
parent reply Moritz Warning <moritzwarning web.de> writes:
On Mon, 21 Jul 2008 18:23:36 +0000, BCS wrote:

 Reply to Moritz,
 
 I have a global toString template function that is also used for
 various
 enums.
 If the toString is used for an unknown Type it's supposed to print out
 an error message at compile time (static assert). Now I face the
 problem that toString is used for some enum I haven't modified toString
 for, but I can't identify the the enums name. All I get is the base
 type int, which is pretty useless. I can search my entire codebase and
 make a list of all enum types it is used for. But that's pretty hard
 for some big templates engines.
 
 Is there a workaround?
 
 
A little more info might be useful. As a starting point I'll assume the toString is something like this: char[] toString(T)(T arg)... { static if(is(T == type1)) {something} else static if(is(T type2)) {something} ... else static assert(false,"can't use "~T.stringof); } and that the assert is giving something useless. Is that the case or are you taking a different approach?
^ Yes, that's the approach I use and the problem that gives me a headache.
Jul 21 2008
parent reply BCS <ao pathlink.com> writes:
Reply to Moritz,


 ^ Yes, that's the approach I use and the problem that gives me a
 headache.
 
Well I think you're toast: this test cases fails enum Foo{a} static assert("Foo" == Foo.stringof, "'Foo' == '"~Foo.stringof~"'"); Might be a bug, but it might already be reported.
Jul 21 2008
parent reply Moritz Warning <moritzwarning web.de> writes:
On Mon, 21 Jul 2008 20:42:41 +0000, BCS wrote:

 Reply to Moritz,
 
 
 ^ Yes, that's the approach I use and the problem that gives me a
 headache.
 
 
Well I think you're toast: this test cases fails enum Foo{a} static assert("Foo" == Foo.stringof, "'Foo' == '"~Foo.stringof~"'"); Might be a bug, but it might already be reported.
I'm pretty sure it was reported already. :F
Jul 21 2008
parent reply BCS <ao pathlink.com> writes:
Reply to Moritz,

 On Mon, 21 Jul 2008 20:42:41 +0000, BCS wrote:
 
 Reply to Moritz,
 
 ^ Yes, that's the approach I use and the problem that gives me a
 headache.
 
Well I think you're toast: this test cases fails enum Foo{a} static assert("Foo" == Foo.stringof, "'Foo' == '"~Foo.stringof~"'"); Might be a bug, but it might already be reported.
I'm pretty sure it was reported already. :F
If you can find it you might add a comment in the hope that it will get fixed sooner.
Jul 22 2008
parent Moritz Warning <moritzwarning web.de> writes:
On Tue, 22 Jul 2008 16:59:01 +0000, BCS wrote:

 Reply to Moritz,
 
 On Mon, 21 Jul 2008 20:42:41 +0000, BCS wrote:
 
 Reply to Moritz,
 
 ^ Yes, that's the approach I use and the problem that gives me a
 headache.
 
Well I think you're toast: this test cases fails enum Foo{a} static assert("Foo" == Foo.stringof, "'Foo' == '"~Foo.stringof~"'"); Might be a bug, but it might already be reported.
I'm pretty sure it was reported already. :F
If you can find it you might add a comment in the hope that it will get fixed sooner.
Here it is: http://d.puremagic.com/issues/show_bug.cgi?id=1610
Jul 22 2008