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
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.
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
when
 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
when
 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.
begin 666 build.bat M9&UD("UC(&AE;'!E<G,N9 T*;&EB(&UY;&EB("LM:&5L<&5R<RYO8FHL+ T* M9&UD("UC(&UA:6XN9 T*<V5T($Q)0CUC.EQD;61<;&EB.V,Z7&1M7&QI8 T* M;&EN:R!M86EN+F]B:BQM86EN+"QM>6QI8BMP:&]B;W,K<VYN*W5U:60O;F]I ` end begin 666 helpers.d M("D 24E$($E)1%])4W1O<F%G93L-" T*+R\ 9&5B=6=G:6YG(&]N;'D-"FEM M:6YD:6YG*"!,.$-/32!)(#H 3#A M24E$7TE5;FMN;W=N(&EF7VED.PT*"6%L:6%S($E5;FMN;W=N(&EF7W1Y<&4[ M;G1E<F9A8V5":6YD:6YG*"!,.$-/32!)(#H 3#A M>2 I('L-" EA;&EA<R!,.$-/32Y)56YK;F]W;B!I9E]S=7!E<CL-" EA;&EA M<R!)241?24-L87-S1F%C=&]R>2!I9E]I9#L-" EA;&EA<R!)0VQA<W-&86-T M0V]M248 .B!B:6YD:6YG7W-U<&5R+DPX0V]M248L(&EF7W1Y<&4 >PT*"7T- M"GT-" T*=&5M<&QA=&4 3#A);G1E<F9A8V4H($PX0T]-($D .B!,.$-/32Y) M56YK;F]W;B I('L-" EA;&EA<R!I;G-T86YC92!,.$EN=&5R9F%C94)I;F1I M;F<H($D *2!B:6YD:6YG.PT*"4A215-53%0 8V%S=%]T;R 1U5)1" J(')I M:60L($]B:F5C="!O+"!V;VED("HJ('!P=B I('L-" D):68 *" J<FEI9" ] M"7)E='5R;B!%7TY/24Y415)&04-%.PT*"7T-" EA;&EA<R!)56YK;F]W;B!, M.$-O;4EN=&5R9F%C93L-"GT-" T*=&5M<&QA=&4 3#A);G1E<F9A8V4H($PX M*"!)("D 8FEN9&EN9SL-" E(4D5354Q4(&-A<W1?=&\H($=5240 *B!R:6ED M8FEN9&EN9RYI9E]I9" I('L-" D)"2IP<'8 /2 H8FEN9&EN9RYI9E]T>7!E M3#A);G1E<F9A8V4H(&)I;F1I;F<N:69?<W5P97( *2YC87-T7W1O*"!R:6ED M23$L($PX0T]-($DR("D >PT*"6%L:6%S(&EN<W1A;F-E($PX26YT97)F86-E M0FEN9&EN9R 23$ *2!B:6YD:6YG,3L-" EA;&EA<R!I;G-T86YC92!,.$EN M7W1O*"!'54E$("H <FEI9"P 3V)J96-T(&\L('9O:60 *BH <'!V("D >PT* M"0EI9B H(%-?3TL /3T :69A8V4Q+F-A<W1?=&\H(')I:60L(&\L('!P=B I M.$-O;4EN=&5R9F%C92 Z(&)I;F1I;F<R+DPX0V]M248L(&)I;F1I;F<Q+FEF M7W1Y<&4 >PT*"7T-"GT-" T*=&5M<&QA=&4 3#A);G1E<F9A8V4H($PX0T]- M($DQ+"!,.$-/32!),BP 3#A M3#A);G1E<F9A8V4H($DQ("D :69A8V4Q.PT*"6%L:6%S(&EN<W1A;F-E($PX M*"!'54E$("H <FEI9"P 3V)J96-T(&\L('9O:60 *BH <'!V("D >PT*"0EI M9B H(%-?3TL /3T :69A8V4Q+F-A<W1?=&\H(')I:60L(&\L('!P=B I*0T* M;4EN=&5R9F%C92 Z(&)I;F1I;F<R+DPX0V]M248L(&)I;F1I;F<Q+FEF7W1Y M<&4 >PT*"7T-"GT-" T*=&5M<&QA=&4 3#A);G1E<F9A8V4H($PX0T]-($DQ M+"!,.$-/32!),BP 3#A M:6YS=&%N8V4 3#A);G1E<F9A8V4H($DR+"!)-" I(&EF86-E,CL-" E(4D53 M54Q4(&-A<W1?=&\H($=5240 *B!R:6ED+"!/8FIE8W0 ;RP =F]I9" J*B!P M9F%C92!,.$-O;4EN=&5R9F%C92 Z(&)I;F1I;F<R+DPX0V]M248L(&)I;F1I ` end begin 666 main.d M+R]I;7!O<G0 =VEN,S(N8V]M+D],14E$3#L-"B\O:6UP;W)T('=I;C,R+F-O M;2Y-4TA434A35#L- M=W,I(&%L:6%S($E5;FMN;W=N($Q054Y+3D]73CL-"FEM<&]R="!H96QP97)S M;4]B:F5C="P 0V%N4W1O<F%G92Y,.$-O;4EN=&5R9F%C90T*>PT*+R]C;&%S M<R!&86ME4W1O<F%G92 Z($-O;4]B:F5C="P 25-T;W)A9V4 >PT*97AT97)N M("A7:6YD;W=S*3H-" E(4D5354Q4(%%U97)Y26YT97)F86-E*$E)1"H <FEI M=&\H(')I:60L('1H:7,L('!P=B I.PT*"7T-"B ("!(4D5354Q4($-R96%T M94EN<W1A;F-E*$E5;FMN;W=N(%5N:T]U=&5R+"!)240J(')I:60L('9O:60J M($A215-53%0 3&]C:U-E<G9E<BA"3T],(&9,;V-K*0T*"7L-" D)<F5T=7)N M($5?3D]424U03#L- C("D-"GL-" ER971U<FX ,#L- ` end
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
begin 666 helpers.d M("D 24E$($E)1%])4W1O<F%G93L-" T*+R\ 9&5B=6=G:6YG(&]N;'D-"FEM M:6YD:6YG*"!,.$-/32!)(#H 3#A M24E$7TE5;FMN;W=N(&EF7VED.PT*"6%L:6%S($E5;FMN;W=N(&EF7W1Y<&4[ M;G1E<F9A8V5":6YD:6YG*"!,.$-/32!)(#H 3#A M>2 I('L-" EA;&EA<R!,.$-/32Y)56YK;F]W;B!I9E]S=7!E<CL-" EA;&EA M<R!)241?24-L87-S1F%C=&]R>2!I9E]I9#L-" EA;&EA<R!)0VQA<W-&86-T M0V]M248 .B!B:6YD:6YG7W-U<&5R+DPX0V]M248L(&EF7W1Y<&4 >PT*"7T- M"GT-" T*=&5M<&QA=&4 3#A);G1E<F9A8V4H($PX0T]-($D .B!,.$-/32Y) M56YK;F]W;B I('L-" EA;&EA<R!I;G-T86YC92!,.$EN=&5R9F%C94)I;F1I M;F<H($D *2!B:6YD:6YG.PT*"4A215-53%0 8V%S=%]T;R 1U5)1" J(')I M:60L($]B:F5C="!O+"!V;VED("HJ('!P=B I('L-" D):68 *" J<FEI9" ] M"7)E='5R;B!%7TY/24Y415)&04-%.PT*"7T-" EA;&EA<R!)56YK;F]W;B!, M.$-O;4EN=&5R9F%C93L-"GT-" T*=&5M<&QA=&4 3#A);G1E<F9A8V4H($PX M8FEN9&EN9SL-" E(4D5354Q4(&-A<W1?=&\H($=5240 *B!R:6ED+"!/8FIE M"0ER971U<FX 4U]/2SL-" D)?0T*"0ER971U<FX :6YS=&%N8V4 3#A);G1E M<F9A8V4H(&)I;F1I;F<N:69?<W5P97( *2YC87-T7W1O*"!R:6ED+"!O+"!P M0T]-($DR("D >PT*"6EN<W1A;F-E($PX26YT97)F86-E0FEN9&EN9R 23$ M*2!B:6YD:6YG,3L-" EI;G-T86YC92!,.$EN=&5R9F%C94)I;F1I;F<H($DR M3V)J96-T(&\L('9O:60 *BH <'!V("D >PT*"0EI9B H(%-?3TL /3T :69A M4U]/2SL-" D)?0T*"0ER971U<FX :69A8V5?8S(N8V%S=%]T;R <FEI9"P M;F1I;F<R+DPX0V]M248L(&)I;F1I;F<Q+FEF7W1Y<&4 >PT*"7T-"GT-" T* M=&5M<&QA=&4 3#A);G1E<F9A8V4H($PX0T]-($DQ+"!,.$-/32!),BP 3#A M2%)%4U5,5"!C87-T7W1O*"!'54E$("H <FEI9"P 3V)J96-T(&\L('9O:60 M*BH <'!V("D >PT*"0EI9B H(%-?3TL /3T :69A8V4Q+F-A<W1?=&\H(')I M"6EN=&5R9F%C92!,.$-O;4EN=&5R9F%C92 Z(&)I;F1I;F<R+DPX0V]M248L M(&)I;F1I;F<Q+FEF7W1Y<&4 >PT*"7T-"GT-" T*=&5M<&QA=&4 3#A);G1E M<F9A8V4H($PX0T]-($DQ+"!,.$-/32!),BP 3#A M("D >PT*"6EN<W1A;F-E($PX26YT97)F86-E*"!),2P 23, *2!I9F%C93$[ M4D5354Q4(&-A<W1?=&\H($=5240 *B!R:6ED+"!/8FIE8W0 ;RP =F]I9" J M=&5R9F%C92!,.$-O;4EN=&5R9F%C92 Z(&)I;F1I;F<R+DPX0V]M248L(&)I ` end begin 666 build.bat M9&UD("UC(&AE;'!E<G,N9 T*;&EB(&UY;&EB("LM:&5L<&5R<RYO8FHL+ T* M9&UD("UC(&UA:6XN9 T*<V5T($Q)0CUC.EQD;61<;&EB.V,Z7&1M7&QI8 T* M;&EN:R!M86EN+F]B:BQM86EN+"QM>6QI8BMP:&]B;W,K<VYN*W5U:60O;F]I ` end begin 666 main.d M+R]I;7!O<G0 =VEN,S(N8V]M+D],14E$3#L-"B\O:6UP;W)T('=I;C,R+F-O M;2Y-4TA434A35#L- M=W,I(&%L:6%S($E5;FMN;W=N($Q054Y+3D]73CL-"FEM<&]R="!H96QP97)S M="P 0V%N4W1O<F%G92Y,.$-O;4EN=&5R9F%C90T*>PT*+R]C;&%S<R!&86ME M4W1O<F%G92 Z($-O;4]B:F5C="P 25-T;W)A9V4 >PT*97AT97)N("A7:6YD M;W=S*3H-" E(4D5354Q4(%%U97)Y26YT97)F86-E*$E)1"H <FEI9"P =F]I M:60L('1H:7,L('!P=B I.PT*"7T-"B ("!(4D5354Q4($-R96%T94EN<W1A M;F-E*$E5;FMN;W=N(%5N:T]U=&5R+"!)240J(')I:60L('9O:60J*B!P=D]B M3%0 3&]C:U-E<G9E<BA"3T],(&9,;V-K*0T*"7L-" D)<F5T=7)N($5?3D]4 M24U03#L- =" ER971U<FX ,#L- ` end
Aug 07 2003