digitalmars.D.learn - templates in libraries
- Charlie (17/17) Jun 04 2005 I have a library with one template function in it
- John Reimer (8/43) Jun 04 2005 Is the template in a file by itself?
- Charlie (11/54) Jun 04 2005 Hey John,
- Charlie (12/55) Jun 04 2005 An 'slightly' better soloution is to put that int* call in a mixin
- J C Calvarese (7/15) Jun 04 2005 Hopefully Walter is able to find a fix for this problem at some point. I...
- John Reimer (4/19) Jun 05 2005 Yeah... that does look a little cleaner! Nice one!
I have a library with one template function in it template array_case(T) { void array_change_key_case ( T[ char [] ] map) { foreach ( inout char [] keys;map.keys ) { keys = std.string.tolower(keys ); } } } However when I build the lib, I get the error Symbol Undefined _D3phd5array13array_case_Aa21array_change_key_caseFHAaAaZv If i eliminate the template and just make them functions it works fine. What is the rule with templates in libraries, I have to call the template somewhere in the code for it to generate stuff or ? Charlie
Jun 04 2005
Charlie wrote:I have a library with one template function in it template array_case(T) { void array_change_key_case ( T[ char [] ] map) { foreach ( inout char [] keys;map.keys ) { keys = std.string.tolower(keys ); } } } However when I build the lib, I get the error Symbol Undefined _D3phd5array13array_case_Aa21array_change_key_caseFHAaAaZv If i eliminate the template and just make them functions it works fine. What is the rule with templates in libraries, I have to call the template somewhere in the code for it to generate stuff or ? CharlieIs the template in a file by itself? I reported this problem earlier; see post "Hair-pulling, D, and Optlink" Walter game the solution for dealing with this very real shortcoming in OMF libraries containing templates: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/23701 I imagine that's what your problem was. -JJR
Jun 04 2005
Hey John, That did work thanks :). I remember reading something about this but forget the title. This is pretty rough , I wonder though is OMF the only format that suffers from this ? I don't know enough about C++ templates to guess how they do it . Charlie "John Reimer" <brk_6502 yahoo.com> wrote in message news:d7t782$a6t$1 digitaldaemon.com...Charlie wrote:_D3phd5array13array_case_Aa21array_change_key_caseFHAaAaZvI have a library with one template function in it template array_case(T) { void array_change_key_case ( T[ char [] ] map) { foreach ( inout char [] keys;map.keys ) { keys = std.string.tolower(keys ); } } } However when I build the lib, I get the error Symbol UndefinedtemplateIf i eliminate the template and just make them functions it works fine. What is the rule with templates in libraries, I have to call thesomewhere in the code for it to generate stuff or ? CharlieIs the template in a file by itself? I reported this problem earlier; see post "Hair-pulling, D, and Optlink" Walter game the solution for dealing with this very real shortcoming in OMF libraries containing templates: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/23701 I imagine that's what your problem was. -JJR
Jun 04 2005
An 'slightly' better soloution is to put that int* call in a mixin int comdatKludge = 0; template kludge () { int * kludge = &comdatKludge; } into the library, then the client just calls mixin kludge; "John Reimer" <brk_6502 yahoo.com> wrote in message news:d7t782$a6t$1 digitaldaemon.com...Charlie wrote:_D3phd5array13array_case_Aa21array_change_key_caseFHAaAaZvI have a library with one template function in it template array_case(T) { void array_change_key_case ( T[ char [] ] map) { foreach ( inout char [] keys;map.keys ) { keys = std.string.tolower(keys ); } } } However when I build the lib, I get the error Symbol UndefinedtemplateIf i eliminate the template and just make them functions it works fine. What is the rule with templates in libraries, I have to call thesomewhere in the code for it to generate stuff or ? CharlieIs the template in a file by itself? I reported this problem earlier; see post "Hair-pulling, D, and Optlink" Walter game the solution for dealing with this very real shortcoming in OMF libraries containing templates: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/23701 I imagine that's what your problem was. -JJR
Jun 04 2005
In article <d7takf$c4j$1 digitaldaemon.com>, Charlie says...An 'slightly' better soloution is to put that int* call in a mixin int comdatKludge = 0; template kludge () { int * kludge = &comdatKludge; } into the library, then the client just calls mixin kludge;Hopefully Walter is able to find a fix for this problem at some point. I've added some more information to http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Template to help explain the problem and some possible solutions (basically, I cut-and-pasted some of these posts into the Wiki). jcc7
Jun 04 2005
Charlie wrote:An 'slightly' better soloution is to put that int* call in a mixin int comdatKludge = 0; template kludge () { int * kludge = &comdatKludge; } into the library, then the client just calls mixin kludge;Yeah... that does look a little cleaner! Nice one! Although it does advertise the fact that their is a kludge! :-) -JJR
Jun 05 2005