Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Doesn't Boost have a number of header-only libs? I believe there is a header-only regex implementation for example.


C++ is a little different in that templates have to go in header files. A lot of template-based C++ libraries are entirely templates in header files.

It's weird because it does feel like it violates the separation of interface and implementation. On the other hand, it's really efficient. It has the advantages of doing generics with the C preprocessor (efficiency and de-duplication of code, if nothing else), minus many of the disadvantages of doing generics with the C preprocessor.

Putting non-template code or data in headers is something I've seen people do for expediency, but it's more trouble than it's worth IMO. As soon as two files in the same project include it, you risk a future headache.


The compiled result of template-heavy C++ can be very efficient, but the compilation process is notoriously inefficient. Just to be clear :)


Technically you can put the template definition in a separate translation unit and rely on explicit instantiation. The linker will tell you exactly what you need to instantiate. It is tedious and seldomly done.

/Pedantic




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: