I'm developing a C++ library that makes heavy uses of templates. For most of the classes, all the code resides in some .hpp
file that will be #include
d directly by client code. There are two things that I'm worrying about:
Is there some design pattern for moving implementation code to the "background"? When I design non-template classes I often separate the "interface" class and the implementation class, and the former will delegate to the latter by doing something like
getImpl()->foo()
, so that implementation code can be dynamically linked to. I'm not sure how to do this for templates. Probably dynamic linking just doesn't make sense for template, I think?Are big template headers (> 1000 lines) common? Or is that bad? If it's bad, what can I do with it?
I am aware of this question How to reduce output size of template-heavy C++ code?, but I think we are asking about different things: the OP of that question is trying to reduce the size of the output, while I am trying to reduce the size of my library headers themselves.
UPDATE: For example, if you were to design std::vector
, how would you organize its interface & implementation (if needed)?