F
feverzsj
Since the separation model seems make nothing cheap, here ,we only
talk about the file organization under the inclusion model.
IMO, the way to organize template source code should try to achieve
two goals, a clear interface and minimizing the compilation
dependences and time if possible.
It is aways easy to archive a "clear look" interface, using a
interface/impl idiom with a impl data member or or impl base or
anything possible. But include them all before the instantiation
point.
For the 2nd goal, forgive my ignorance, I can only figure out two
basic points, lazy instantiation and specialization. Lazy
instantiation is related to dependent name. For example, if the impl
part is related to dependent name, we can offer the definition until
the instantiation point. As for specialization, clearly, it helps to
decrease the compilation time and also the code size(use with the
partial specialization). The explicit instantiation also helps to
decrease the compilation time, but it makes little sense to generic
programming.
Combining all of them, it becomes much tricky(e.g. the pimpl of
templte) to achieve both goals. We have to design the template
architecture carefully, make a appropriate granularity of abstraction
to benefit the lazy instantiation and specialization...
This post is yet a very crude overview on the organization of
template source code, I'll add some detailed idiom and example later.
Also, I hope you can post your notion, suggestion, example and any
related comments.
talk about the file organization under the inclusion model.
IMO, the way to organize template source code should try to achieve
two goals, a clear interface and minimizing the compilation
dependences and time if possible.
It is aways easy to archive a "clear look" interface, using a
interface/impl idiom with a impl data member or or impl base or
anything possible. But include them all before the instantiation
point.
For the 2nd goal, forgive my ignorance, I can only figure out two
basic points, lazy instantiation and specialization. Lazy
instantiation is related to dependent name. For example, if the impl
part is related to dependent name, we can offer the definition until
the instantiation point. As for specialization, clearly, it helps to
decrease the compilation time and also the code size(use with the
partial specialization). The explicit instantiation also helps to
decrease the compilation time, but it makes little sense to generic
programming.
Combining all of them, it becomes much tricky(e.g. the pimpl of
templte) to achieve both goals. We have to design the template
architecture carefully, make a appropriate granularity of abstraction
to benefit the lazy instantiation and specialization...
This post is yet a very crude overview on the organization of
template source code, I'll add some detailed idiom and example later.
Also, I hope you can post your notion, suggestion, example and any
related comments.