Foo!("a").????? == `Foo!("a")`

Nick Sabalausky a at a.a
Tue Dec 8 11:47:39 PST 2009


"Nick Sabalausky" <a at a.a> wrote in message 
news:hff1qc$1h6e$1 at digitalmars.com...
>I don't suppose there's an easy general way to get the paramaters of a 
>templated type just from the type itself? Ie, a way to get around this:
>
> class Foo(char[] str) {}
> static assert(Foo!("a").stringof != Foo!("b").stringof)
> // ^ fails because it evaluates to "Foo" != "Foo"
>
> I can probably work around it in my current case by sticking str into a 
> const member of Foo and using that together with .stringof, but thought 
> I'd see if there was a better way.
>
>

Just for reference for anyone interested, in my own case I've worked around 
it like this:

class Foo(char[] str)
{
    static const char[] StringOf = "Foo!("~str.stringof~")";
}
static assert(Foo!("a").StringOf == `Foo!("a")`);

Similar workarounds can be done for other template signatures, like a 
custom-made function for enums, or a "static if(StringOf exists) use 
StringOf else use stringof" for general T types.




More information about the Digitalmars-d-learn mailing list