Thread overview
Unexpected type names with template typedefs
Apr 29, 2008
Simen Kjaeraas
Apr 29, 2008
BCS
Apr 29, 2008
Simen Kjaeraas
Apr 29, 2008
BCS
April 29, 2008
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
April 29, 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.


April 29, 2008
On Tue, 29 Apr 2008 05:45:18 +0200, BCS <ao@pathlink.com> wrote:

> 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.

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
April 29, 2008
Simen Kjaeraas wrote:
> BCS wrote:
> 
>> 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

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;