Which headers in the C++ standard library are guaranteed to include another header?

This answer ignores C headers – both the <meow.h> and <cmeow> ones. Of the C++ library headers (all references are to N4659):

<initializer_list> is guaranteed to be included by:

<iostream> is guaranteed to include <ios>, <streambuf>, <istream>, and <ostream> (§30.4.1 [iostream.syn]).

<ios> is guaranteed to include <iosfwd> (§30.5.1 [ios.syn]).

<bitset> is guaranteed to include <string> and <iosfwd> (§23.9.1 [bitset.syn]).

The free function templates std::begin, std::end, the C++14 c-, r-, and cr- versions, and the C++17 free function templates std::size, std::empty and std::data nominally reside in <iterator>, but are also available if any of the following headers is included: <array>, <deque>, <forward_list>, <list>, <map>, <regex>, <set>, <string>, <unordered_map>, <unordered_set>, and <vector> (§27.7 [iterator.range], §27.8 [iterator.container]).

When <string_view> is included, the *begin and *end functions, and the two generic std::swap overloads defined in [utility.swap] (swap(T&, T&) and swap(T (&a)[N], T (&b)[N])) are guaranteed to be available. size/empty/data, however, are not. (§24.4.1 [string.view.synop]).

Leave a Comment