I am developing math software with algorithms that work for universal integer types such as machine ints or GMP integers. Performance usually requires working with machine ints, but if there is an overflow, then you can try switching to GMP; perfect at runtime. So far, the entire program is written as a template over an integer type. As the library grows, the pain intensifies:
- Compilation time and memory consumption are out of control.
- Error messages during compilation are less useful.
- Debugging is more painful.
- All code is in header files.
I can think of the following solution. Code refactoring depends on a fixed type that is typedef'ed through a compile-time macro. Then create several copies of the library, one for each integer type, and combine them together in an executable file. The downside seems to be that I need a library interface for myself.
Short question: what are the design patterns for situations in which almost the entire program depends on the type?
source share