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:
- Most libraries will turn out to have very predictable include patterns.
- 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)
- 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.
- 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.

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.