c++ - 该标准是否指定哪些 header 包含其他 header ?

标签 c++ standards header-files

我正在参加在线编码竞赛,我的想法是找到一个名称比 <iostream> 短的 header 但包括 <iostream> .好吧,直到现在我才成功,但这让我想知道:

标准是否指定哪些 header 包含其他 header ?

例如,在 <iostream>cplusplus状态:

Including this header may automatically include other headers, such as <ios>, <streambuf>, <istream>, <ostream> and/or <iosfwd>.

但是,当我寻找 <ios>没有诸如“此 header 可能包含在 <iostream> 中”之类的声明。对于某些 header ,我可以想象它们需要包含其他 header 才能正常工作。如果是这种情况,我希望标准能够说明 header 如何相互依赖(例如,必须避免循环依赖)。还是标准只是确保不存在此类依赖关系,这取决于实现?

最佳答案

关于哪些 header 可以被其他 header 包含的一般规则是:有一些 header 被指定为自动包含,除此之外,它取决于实现,不需要记录。

17.6.5.1 Conforming implementations [conforming]

17.6.5.2 Headers [res.on.headers]

1 A C++ header may include other C++ headers. A C++ header shall provide the declarations and definitions that appear in its synopsis. A C++ header shown in its synopsis as including other C++ headers shall provide the declarations and definitions that appear in the synopses of those other headers.

关于“在其概要中显示为包含其他 C++ header ”的规则适用于:

  • <utility> , <string> , <array> , <deque> , <forward_list> , <list> , <vector> , <map> , <set> , <unordered_map> , <unordered_set> , <queue> , <stack> , <algorithm> , <random> , <valarray> , <regex>包括 <initializer_list> .
  • <bitset>包括 <string> , <iosfwd> .
  • <iostream>包括 <ios> , <streambuf> , <istream> , <ostream> .
  • <ios>包括 <iosfwd> .

然而,尽管例如<ios>显示为包括 <iosfwd> ,实现可能能够在不实际包含它的情况下实现要求,并且根据 [res.on.headers],这很好。在大多数情况下,实现是否包含其他 header 没有任何区别,只要声明的函数和类型可访问即可。

关于c++ - 该标准是否指定哪些 header 包含其他 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38421334/

相关文章:

c++ - 调用QML处理程序,但使用 “undefined” c++信号参数

c++ - 如何使用OpenCV C++检测图像中有多少阶梯

c++ - pygccxml 中是否有 Python Clang 包装器来包装 GCC-XML?

c - C 中的整数是假定由硬件规范处理还是由软件处理?

c++ - 在头文件中定义独立函数 - C++

c++ - 在 C++ (gcc) 中如何表示 float 和 double?

definition - syslog 是日志记录标准还是协议(protocol)标准?

c++ - Turbo C++ 和 Dev-C++ 中 C 和 C++ 语言的标识符的最大长度

c - 我在哪里可以找到系统上标准库的头文件?

c - 头文件typedef定义