Toy example to better explain my problem:
I have my library, which has my custom struct, e.g. StructProgrammer
and my templateProgrammer.hpp
file with:
template <typename T> TemplateProgrammer {
};
Where I know that 90% of the time, people will use the template class as:
TemplateProgrammer<StructProgrammer>
However, we want people to also be able to use my template with their own custom struct, e.g.
TemplateProgrammer<StructUser>
Since it is a template, that is not a problem. But it takes a lot of time for the user to compile the whole program because it has to compile this heavy TemplateProgrammer
class every time he changes his own main.cpp
. So a possible solution could be to create templateProgrammer.cpp
, and implement there the code and initialize the class:
template class TemplateProgrammer<StructUser>;
Nevertheless, this would make the user not being able to compile this function for his own StructUser
:
TemplateProgrammer<StructUser>
So what I would like to do is to add the *.cpp code for my TemplateProgrammer<StructProgrammer>
, such as for most user it will be fast to compile, while keeping the possibility for specialized users to use their own structs (for custom structs I do not care if it takes time to compile or not because that is not possible to avoid).
The point is, is this possible? Can the template of my library be pre-compiled for a specific class and at the same time can it keep the possibility of being compiled for new classes? If so, how?
Otherwise, what is the best way to proceed?