Thread overview
Q: Hiding template implementation
Jun 12, 2007
Myron Alexander
Jun 12, 2007
Kirk McDonald
Jun 12, 2007
Myron Alexander
June 12, 2007
Hello.

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

Regards,

Myron.
June 12, 2007
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
June 12, 2007
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.