5 ms·
I don't completely disagree, but templates become a big trap with respect to header files and trying to get static linked files precompiled.
by rileymat2 5y ago
I don't completely disagree, but templates become a big trap with respect to header files and trying to get static linked files precompiled.
- inetknght 5y agoIf you know your types then you can define the templates' bodies into a static library and keep the definitions there.
- boardwaalk 5y agoThe problems being: * External libraries don't do this. See: All those "header-only" libraries you see, starting back with boost * It's a total PITA once the types get complicated Source: Have worked for 10 years on a large codebase with "template auto instantiation" off.
- a_t48 5y agoEigen is the worst for this. :(
- munk-a 5y agoI agree a bunch with this. Templates can actually get really complicated quickly... In C++ if you want to generate the bytes to execute FooBar<string> then you actually need to reference FooBar<string> somewhere in the code to signal its necessary inclusion and later compilation steps can't build this for other types on the fly. If you have very generic and flexible templates defined in a static library the library needs to have actually forced the compilation for all the types you intend to use. So I do agree that templates remain a big pain!