www.digitalmars.com         C & C++   DMDScript  

D - template alias and instances

reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
Walter,

if I have the code
template foo( T ) { class bar {.... } }

is there a difference in the way the compiler treats things if I do the
following in a module
alias instance foo(int) foo_int1;
instance foo(int) foo_int2;

are foo_int1 and foo_int2 effectivly the same, or are there reasons to use
one or the other

alias foo_int1.bar bar_int1;
alias foo_int2.bar bar_int2;
alias instance foo(int).bar bar_int3;

would is make a difference which "bar_int" I used here ?
class test : bar_int? { ... }
Aug 02 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
news:bggtlv$fgb$1 digitaldaemon.com...
 Walter,

 if I have the code
 template foo( T ) { class bar {.... } }

 is there a difference in the way the compiler treats things if I do the
 following in a module
 alias instance foo(int) foo_int1;
 instance foo(int) foo_int2;

 are foo_int1 and foo_int2 effectivly the same, or are there reasons to use
 one or the other

They're the same.
 alias foo_int1.bar bar_int1;
 alias foo_int2.bar bar_int2;
 alias instance foo(int).bar bar_int3;

 would is make a difference which "bar_int" I used here ?
 class test : bar_int? { ... }

They're all the same.
Aug 06 2003
parent reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bgrdpm$16pq$1 digitaldaemon.com...
 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:bggtlv$fgb$1 digitaldaemon.com...
 Walter,

 if I have the code
 template foo( T ) { class bar {.... } }

 is there a difference in the way the compiler treats things if I do the
 following in a module
 alias instance foo(int) foo_int1;
 instance foo(int) foo_int2;

 are foo_int1 and foo_int2 effectivly the same, or are there reasons to


 one or the other

They're the same.
 alias foo_int1.bar bar_int1;
 alias foo_int2.bar bar_int2;
 alias instance foo(int).bar bar_int3;

 would is make a difference which "bar_int" I used here ?
 class test : bar_int? { ... }

They're all the same.

that explains why my missing instances from objects example fails even when I declare instances all over the place rather than aliases. is there a way to force the creation within an object file of an instance of a template with given params (I assume the linker would be smart enought to only link the onces needed ? or is there a way to create an object file that is just a ast of the file :) recompiled at link times so templates that are needed get created ?
Aug 07 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
news:bgu2mq$mfg$1 digitaldaemon.com...
 that explains why my missing instances from objects example fails even

 I declare instances all over the place rather than aliases.

Not really. It should generate the instance again, and then the linker should factor out the duplicates. Something else is going wrong for you. If you could make a small example of an instance that is not being generated, I can have a look.
Aug 07 2003
parent reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
I thought I posted it .....

build .bat (as attached)

dmd -c helpers.d
lib mylib +-helpers.obj,,
dmd -c main.d
set LIB=c:\dmd\lib;c:\dm\lib
link main.obj,main,,mylib+phobos+snn+uuid/noi



"Walter" <walter digitalmars.com> wrote in message
news:bgv9ph$1pta$1 digitaldaemon.com...
 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:bgu2mq$mfg$1 digitaldaemon.com...
 that explains why my missing instances from objects example fails even

 I declare instances all over the place rather than aliases.

Not really. It should generate the instance again, and then the linker should factor out the duplicates. Something else is going wrong for you.

 you could make a small example of an instance that is not being generated,

 can have a look.

Aug 07 2003
parent "Mike Wynn" <mike.wynn l8night.co.uk> writes:
fool! (me that is)
posted the version with alias's
save build different files.
still gives

main.obj(main)
 Error 42: Symbol Undefined
_Dhelpers__L8Interface__0_cast_to_FPS8com_GUIDC6Obje
ctPPvZi

"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
news:bgvcev$1s6r$1 digitaldaemon.com...
 I thought I posted it .....

 build .bat (as attached)

 dmd -c helpers.d
 lib mylib +-helpers.obj,,
 dmd -c main.d
 set LIB=c:\dmd\lib;c:\dm\lib
 link main.obj,main,,mylib+phobos+snn+uuid/noi

Aug 07 2003