General method for discovering the answers to "which header should I include" questions in boost official documentation?

Viewed 70

This is an example of countless documentation pages in the Boost.org official docs that completely fail to answer the Question Number Zero: "which header file should I include in order to be able to use this thing"?

What is the secret art of discovering answers to these questions from official boost docs, as opposed to just grepping the sources for definitions?

2 Answers

Note, I'd previously written a fully general response to the question title

To answer the specific example:

Go by the library home page: https://www.boost.org/doc/libs/1_78_0/libs/iterator/doc/ (you can find it from https://www.boost.org/doc/libs/1_78_0/ in case you have trouble guessing the URL).

It will show you a top-level index, and the Specialized Adaptors section mentions function_output_iterator:

enter image description here

Clicking on that link takes you here: https://www.boost.org/doc/libs/1_78_0/libs/iterator/doc/function_output_iterator.html

A fragment from the top of that page: enter image description here

Note: this answers the title: General method for discovering the answers to "which header should I include" questions in boost official documentation?.

I've added a specific answer for your example case: https://stackoverflow.com/a/71236918/85371

My strategy is usually to read the examples, sometimes the tests.

However, this may not be necessary:

  1. Most libraries will turn out to have very predictable include patterns.
  2. Some will even warn you about which headers to include with pragmas (Variant for variant_io.hpp, Bind for bind/bind.hpp to get the new placeholder behaviour, some deprecated headers will hint what to use instead)
  3. Many libraries (the majority?) include a header-reference section with hyperlinks for symbols named throughout. Just click on the type/function and inspect the page link to see what header.
  4. Most documentation samples are actually inlined from the example sources included

Sadly, some libraries do not have predictable include patterns, or even documentation coverage of some aspects. One example, in my experience, would be Boost Geometry. Luckily, the first approach (by examples and test) usually works. If all else fails you can always come to StackOverflow or the Boost mailing lists.

3. Hyperlinked References

As an example:

Boost Interprocess has its header reference in doc/html/interprocess/indexes_reference.html#boost_interprocess_header_reference. When you browse the documentation for, say: Managed Heap Memory: Boost.Interprocess machinery in heap memory, you will find the mention of "basic_managed_external_buffer" hyperlinks to https://www.boost.org/doc/libs/1_78_0/doc/html/boost/interprocess/basic_managed_ext_idm26635.html in the reference, stating which header it comes from, which again hyperlinks to https://www.boost.org/doc/libs/1_78_0/doc/html/interprocess/indexes_reference.html#header.boost.interprocess.managed_external_buffer_hpp in the header reference.

enter image description here

4. Inlined Documentation Snippets

For most of the libraries I'm aware of, the documentation samples are actually referring to fragments directly taken from working/building example programs. E.g. the documentation snippet at https://www.boost.org/doc/libs/1_78_0/libs/spirit/repository/doc/html/spirit_repository/qi_components/directives/distinct.html#spirit_repository.qi_components.directives.distinct.using_the_distinct_directive_to_match_keywords is actually directly compiled-in from /libs/spirit/repository/example/qi/distinct.cpp, lines 26-35:

//[qi_distinct_description_ident
{
    std::string str("description ident");
    std::string::iterator first(str.begin());
    bool r = qi::phrase_parse(first, str.end()
      , distinct(alnum | '_')["description"] >> -lit("--") >> +(alnum | '_')
      , space);
    BOOST_ASSERT(r && first == str.end());
}
//]

To find the full, self-contained, code, there's often a link from the documentation page, but sometimes a quick file search helps. For example, the previous sample does link to the example source file, but otherwise a grep "description ident" works.

Related