C++ header-only template library

后端 未结 9 2106
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 20:21

Looking at this project (http://www.savarese.com/software/libssrckdtree/) I found the definition \"C++ header-only template library\". At the moment I have basic C++ knowled

相关标签:
9条回答
  • 2020-12-09 21:11

    For template libraries, it's possible to provide all of the functionality in just header (.h files) because traditionally compilers needed the full definition of the template class in order to instantiate for a given type. There is nothing to put in a library unless the library is going to provide pre-instantiated versions or if there is some portion of the template library that doesn't need to be templated.

    0 讨论(0)
  • 2020-12-09 21:11

    It's "header only" because it contains no separate .cpp files, only .h files and so you can just #include all the library code into your code.

    This can be advantageous since you don't have to link against a static library which can be very painful.

    0 讨论(0)
  • 2020-12-09 21:12

    It means that all of the code is in header files; there are no libraries associated with the library. What that means in practice depends—in the worst case, it means that the author has never even compiled the code:-). Most likely, it means that the code has never been tested with the exact combination of compiler, version and options that you use, and that compile times will shoot way up. On the other hand, it means that you can use the library even if the author doesn't have access to the same compiler as you, and you're not forced to use whatever options he used when he compiled the library. Or alternatively, if it is open source, you don't have to build the library yourself.

    0 讨论(0)
提交回复
热议问题