www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



digitalmars.D.learn - Unexpected type names with template typedefs

↑ ↓ ← "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
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
↑ ↓ BCS <ao pathlink.com> writes:
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
↑ ↓ "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
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
Apr 28 2008
↑ ↓ → BCS <BCS pathlink.com> writes:
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;
Apr 29 2008