www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - templates in libraries

reply "Charlie" <charles jwavro.com> writes:
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
parent reply John Reimer <brk_6502 yahoo.com> writes:
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 ?
 
 
 Charlie
 
 
Is 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
next sibling parent "Charlie" <charles jwavro.com> writes:
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:
 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
Is 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
prev sibling parent reply "Charlie" <charles jwavro.com> writes:
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:
 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
Is 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
next sibling parent J C Calvarese<technocrat7 gmail.com> writes:
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
prev sibling parent John Reimer <brk_6502 yahoo.com> writes:
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