"Simen kjaeraas" <simen.kja...@gmail.com> wrote in message news:op.u4h55pbcvxi...@biotronic-pc.home... > On Sun, 06 Dec 2009 02:36:58 +0100, Nick Sabalausky <a...@a.a> wrote: > >> 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. > > Use more parentheses. ( Foo!( "a" ) ).stringof gives the right result. Of > course, this still seems rather weird. >
Not in D1 unfortunately (or at least 1.051): ----------------------------------- class Foo(char[] str) {} pragma(msg, `Foo!("a").stringof: ` ~ Foo!("a").stringof); pragma(msg, `Foo!("b").stringof: ` ~ Foo!("b").stringof); pragma(msg, `(Foo!("a")).stringof: ` ~ (Foo!("a")).stringof); pragma(msg, `(Foo!("b")).stringof: ` ~ (Foo!("b")).stringof); template Bar1(T) { const char[] Bar1 = T.stringof; } template Bar2(T) { const char[] Bar2 = (T).stringof; } pragma(msg, `Bar1!(Foo!("a")): ` ~ Bar1!(Foo!("a"))); pragma(msg, `Bar1!(Foo!("b")): ` ~ Bar1!(Foo!("b"))); pragma(msg, `Bar2!(Foo!("a")): ` ~ Bar2!(Foo!("a"))); pragma(msg, `Bar2!(Foo!("b")): ` ~ Bar2!(Foo!("b"))); void main() {} ----------------------------------- Compiler output: ----------------------------------- Foo!("a").stringof: class Foo Foo!("b").stringof: class Foo (Foo!("a")).stringof: Foo (Foo!("b")).stringof: Foo Bar1!(Foo!("a")): Foo Bar1!(Foo!("b")): Foo Bar2!(Foo!("a")): Foo Bar2!(Foo!("b")): Foo ----------------------------------- Odder still, notice the "class " prepended to a couple of them. stringof truly is shit atm.