C ++ Template Semis

An example game to better explain my problem:

I have my library that has my custom framework for example. StructProgrammer

and my templateProgrammer.hpp

file:

template <typename T> TemplateProgrammer {
};

      

Where I know 90% of the time people will use the templates class like:

TemplateProgrammer<StructProgrammer>

      

However, we want people to be able to use my template as well with their own custom structure, eg.

TemplateProgrammer<StructUser>

      

Since this is a template, this is not a problem. But it takes a long time for the user to compile the whole program because he has to compile this heavy class TemplateProgrammer

every time he changes his own main.cpp

. So a possible solution would be to create templateProgrammer.cpp

and implement the code there and initialize the class:

template class TemplateProgrammer<StructUser>;

      

However, this would make it impossible for the user to compile this function for their own StructUser

:

TemplateProgrammer<StructUser>

      

So, I would like to add * .cpp code for mine TemplateProgrammer<StructProgrammer>

, for example it will compile quickly for most users, keeping the ability for specialized users to use their own structs (for custom structs I don't care if it takes time to compile or not, because this cannot be avoided).

The point is, is it possible? Is it possible to precompile my library template for a specific class and at the same time keep compileability for new classes? If so, how?

Otherwise, what's the best way to proceed?

+3


source to share





All Articles