0

Like a person drawn into a drug addiction but deluding himself he's trying to quit and cut down, so am I drawn to using more and more of the Boost library. So, I like to lie to myself and pretend it's very little of Boost and I can quit anytime I like!

Seriously, though, occasionally I'm considering "hmm, should I use Boost for that? I know there's a header/library with a relevant name..." Now, what I want is to be able to tell myself "are you crazy? That means dragging in an incredible amount of heavy-template voodoo you really do not want dragging down your compiler."

So, how can I do that? Suppose I have either a boost construct (like a specific function or class), or perhaps a single boost file which I'm including - how can I tell "how much" including that file and/or using that construct drags in to my compilation process?

Obviously starting to browse the source is a way, but I would like something more automatic and coarse-grained, which can differentiate between "oh, this is nothing, 1-2 short files and the templates won't even get instantiated" and "expect massive pain, breakage when combining with CUDA, redundant functionality with the standard library" etc.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • 2
    Maybe use [bcp](http://www.boost.org/doc/libs/1_60_0/tools/bcp/doc/html/index.html)? – Kerrek SB May 07 '16 at 18:42
  • 1
    If you have g++ you can do: `echo "#include "|g++ -x c++ -E -`. Then pipe that to a line counter etc... – Galik May 07 '16 at 18:43
  • @Galik Interesting approach, maybe the `-MM` options family could come in handy as well. – πάντα ῥεῖ May 07 '16 at 18:48
  • @Galik: Not nearly robust enough... Line breaks are not a very good measure of complexity. Also, I will always pull into that numerous system headers which I'm including anywhere – einpoklum May 07 '16 at 19:30
  • @einpoklum You need to do some further processing which is why I said to pipe it. For example you can pipe it to `grep 'boost' to select only boost headers, use `cut -d ' ' -f 3` to select only the header path and then do a `sort -u` to get rid of the empty lines and provide a unique list of boost headers. Then you can count the lines with `wc -l` giving the number of boost headers dragged in. – Galik May 07 '16 at 20:21
  • @KerrekSB BCP tends to pull in a lot more than is actually used. Better have the [preprocessor list all included headers](http://stackoverflow.com/questions/4479049/show-include-equivalent-option-in-g) and process the results. In general, include only what you use (not the top level headers that pull in the entire library), use forward declarations, and keep the heavy stuff (like spirit) tucked inside implementation. Consider the cost of reusing something from boost, to either implementing (and testing) it yourself or adding another third party dependency. – Dan Mašek May 08 '16 at 14:59

0 Answers0