I am creating a C template library which I intend to use as a vital component in a number of future projects. Due to the size of the library, I am dividing the code between a number of files, some of which are forward declarations and prototypes and some of which are "implementations." Some classes in the library are strictly internal and are not intended to be directly accessed by users (i.e. future me).
There seems to (more or less) be an accepted standard directory structure for compiled C libraries (decent thread on the topic: Directory structure for a C library) but in the case of a template library, all files are technically headers.
Is there an accepted directory structure for template libraries? Should I put the public header in /include and private headers and "implementations" in /src ?
P.S. I'm sorry if this is common knowledge. If there is a resource I have missed that addresses this topic, feel free to link it and this thread can be promptly closed.
CodePudding user response:
There are a few examples of header only libraries which put everything in the include
directory. When it comes to private implementations, there may be a sub-directory or namespace which makes this intent clear to the consumer (something like internal
, details
, or impl
).
Adding an accompanying namespace should help separate these implementation details out from the templates the user is expected to consume.
One example I can immediately think of is Cereal.
As a user, when consuming a header only library, I'd expect to just have to add YourProject/include
to my include path to be able to consume your templates.