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

后端 未结 1 1403
暖寄归人
暖寄归人 2020-11-29 04:48

The C++ standard library headers may include each other in unspecified ways, so programmers generally shouldn\'t depend on one header including another. In a few cases, howe

相关标签:
1条回答
  • 2020-11-29 05:52

    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:

    • <utility> (§23.2.1 [utility.syn])
    • <string> (§24.3.1 [string.syn])
    • <array> (§26.3.2 [array.syn])
    • <deque> (§26.3.3 [deque.syn])
    • <forward_list> (§26.3.4 [forward_list.syn])
    • <list> (§26.3.5 [list.syn])
    • <vector> (§26.3.6 [vector.syn])
    • <map> (§26.4.2 [associative.map.syn])
    • <set> (§26.4.3 [associative.set.syn])
    • <unordered_map> (§26.5.2 [unord.map.syn])
    • <unordered_set> (§26.5.3 [unord.set.syn])
    • <queue> (§26.6.2 [queue.syn])
    • <stack> (§26.6.3 [stack.syn])
    • <algorithm> (§28.2 [algorithms.syn])
    • <random> (§29.6.2 [rand.synopsis])
    • <valarray> (§29.7.1 [valarray.syn])
    • <regex> (§31.4 [re.syn])

    <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]).

    0 讨论(0)
提交回复
热议问题