Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
859 views
in Technique[技术] by (71.8m points)

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

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, however, a header is guaranteed to include another header, or make available certain functions that would otherwise require inclusion of another header. What are those cases?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...