digitalmars.D.learn - Unexpected type names with template typedefs
- Simen Kjaeraas (20/20) Apr 28 2008 struct foo(T)
- BCS (4/24) Apr 28 2008 you might be getting a smaller case than what you want, namely the typed...
- Simen Kjaeraas (5/29) Apr 28 2008 That's what I think as well. I'm just wondering if it is correct. Seeing...
- BCS (8/20) Apr 29 2008 I think you might be in undefined territory. Not that it should be
struct foo(T) { T value; } template bar(T) { typedef foo!(T) bar; } void main(string[] args) { writefln((bar!(int)).stringof); // prints 'bar' writefln((bar!(float)).stringof); // prints 'bar' writefln((bar!(bar!(int))).stringof); // prints 'bar' writefln((foo!(int)).stringof); // prints 'foo!(int)' writefln((foo!(float)).stringof); // prints 'foo!(float)' writefln((foo!(foo!(int))).stringof); // prints 'foo!(foo!(int))' } Should not the output of the first three be 'bar!(int)', 'bar!(float)', and 'bar!(bar!(int))'? -- Simen
Apr 28 2008
Reply to Simen,struct foo(T) { T value; } template bar(T) { typedef foo!(T) bar; } void main(string[] args) { writefln((bar!(int)).stringof); // prints 'bar' writefln((bar!(float)).stringof); // prints 'bar' writefln((bar!(bar!(int))).stringof); // prints 'bar' writefln((foo!(int)).stringof); // prints 'foo!(int)' writefln((foo!(float)).stringof); // prints 'foo!(float)' writefln((foo!(foo!(int))).stringof); // prints 'foo!(foo!(int))' } Should not the output of the first three be 'bar!(int)', 'bar!(float)', and 'bar!(bar!(int))'?you might be getting a smaller case than what you want, namely the typedef rater than the name of the template. this might be be related to fully qualified names and such.
Apr 28 2008
On Tue, 29 Apr 2008 05:45:18 +0200, BCS <ao pathlink.com> wrote:Reply to Simen,That's what I think as well. I'm just wondering if it is correct. Seeing as the typedef maps to a template instantiation that would normally be called bar!(Something), I'd expect the typedef to match that name. -- Simenstruct foo(T) { T value; } template bar(T) { typedef foo!(T) bar; } void main(string[] args) { writefln((bar!(int)).stringof); // prints 'bar' writefln((bar!(float)).stringof); // prints 'bar' writefln((bar!(bar!(int))).stringof); // prints 'bar' writefln((foo!(int)).stringof); // prints 'foo!(int)' writefln((foo!(float)).stringof); // prints 'foo!(float)' writefln((foo!(foo!(int))).stringof); // prints 'foo!(foo!(int))' } Should not the output of the first three be 'bar!(int)', 'bar!(float)', and 'bar!(bar!(int))'?you might be getting a smaller case than what you want, namely the typedef rater than the name of the template. this might be be related to fully qualified names and such.
Apr 28 2008
Simen Kjaeraas wrote:BCS wrote:I think you might be in undefined territory. Not that it should be undefined though. IMHO what you are doing /should/ work. p.s. I'd like to see this as well typedef foo!(T) bar(T); or if the args on the right looks to ugly: typedef(T) foo!(T) bar;you might be getting a smaller case than what you want, namely the typedef rater than the name of the template. this might be be related to fully qualified names and such.That's what I think as well. I'm just wondering if it is correct. Seeing as the typedef maps to a template instantiation that would normally be called bar!(Something), I'd expect the typedef to match that name. -- Simen
Apr 29 2008