14

Some boost libraries are header-only, some are not, and for various reasons etc.

Is there a specific reason/design decision why Boost.ProgramOptions is not header-only?

I'm wondering because it claims to be a "small" library in its the documentation and I don't see any system-related reason (like threads or asio).

sigbjornlo
  • 1,033
  • 8
  • 20
Giovanni Funchal
  • 8,934
  • 13
  • 61
  • 110
  • Perhaps my answer is patronising you. Have an upvote so an expert might answer. – Bathsheba Mar 15 '17 at 13:54
  • I don’t know if it needs to do this, but it looks like almost all of the code is in `.cpp` files and it isn’t even attempting to be header-only: https://github.com/boostorg/program_options – Daniel H Mar 24 '17 at 16:34
  • You might want to drop Vladimir Prus (http://vladimirprus.com/) an email to see if he has an answer for you. – sigbjornlo Apr 27 '17 at 08:52
  • I asked the same question to the developer of Boost.Serialization, there is actually no good reason for that in perspective. At the time, people were worried about code bloating and large compilations times. There was no question that any non-template code would be in cpp files. Now these problems are less serious. Once they decided to make separate compilation they abused it and it is now too hard to make it header only because of singletons and static variables, things like that. Although sometimes is possible to make it header only by copying cpp code (from source) into hpp. Want to try? – alfC Apr 22 '20 at 09:22
  • Here these is header only library to process program optiosn, it claims to have similar features as Boost.ProgramOptions: https://github.com/rambler-digital-solutions/raconfig . So there is no fundamental reason for not being header-only. There is also CLI11, header only, https://github.com/CLIUtils/CLI11/tree/v0.1 – alfC Apr 22 '20 at 09:23
  • In addition, Boost.ProgramOptions's main component is a parser (like Boost.Serialization) and parsers usually has a lot of static data (lile tables of characters or delimiter). These tends to be put in cpp files, nowadays there are other options, like constexpr strings, etc. – alfC Apr 23 '20 at 06:47
  • One of Boost's biggest parser libraries (boost.spirit) is written completely header only. So it should definitively be possible. Maybe the authors just didn't see it possible back then and now don't want to change it anymore. – Jakob Stark Dec 06 '22 at 08:12

2 Answers2

5

Program Options claims to be small, but it turns out to be the second largest library we were building, after Regex. (It is bigger than boost Filesystem and Thread libraries.) I believe that you should be glad they're building a library for it instead of choking your project with a ton of included headers. Perhaps the author thought it would be small when he started and forgot to change the comment when it continued to grow and add features.

CHKingsley
  • 321
  • 2
  • 9
0

Not all C++ code can be written in just headers due to one-definition-rule violations.

For example, the storage reservation for a static member of a class needs to be in exactly one translation unit (although future C++ standards may obviate that).

The original intention was for Boost to be header only, but they had to quickly relinquish that aspiration.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483