www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Q: Hiding template implementation

reply Myron Alexander <someone somewhere.com> writes:
Hello.

How do you hide the template implementation when compiling a library?

Regards,

Myron.
Jun 12 2007
parent reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Myron Alexander wrote:
 Hello.
 
 How do you hide the template implementation when compiling a library?
 
 Regards,
 
 Myron.

You can't. Templates don't compile to anything on their own. Object code for them is only generated when the template is instantiated. In order to instantiate a template, the code using the template needs full access to the template's source. D's templates are very much like C++'s templates in this respect. The following is somewhat relevant: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12 (Though note it is about C++ and not D, so many of the specifics are different.) -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Jun 12 2007
parent Myron Alexander <someone somewhere.com> writes:
Kirk McDonald wrote:
 You can't. Templates don't compile to anything on their own. Object code 
 for them is only generated when the template is instantiated. In order 
 to instantiate a template, the code using the template needs full access 
 to the template's source.
 
 D's templates are very much like C++'s templates in this respect. The 
 following is somewhat relevant:
 http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12
 (Though note it is about C++ and not D, so many of the specifics are 
 different.)
 

I was hoping there was some clever option I was missing :) I eventually realized that the current implementation does not do what I believe would be a major boon for library writers and users so I started a thread on d.D about creating a new form of binary module. P.S. What do you think of the changes to D-DBAPI, along the lines of what you wanted? Regards, Myron.
Jun 12 2007