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?
c++标准库头可能以未指定的方式包含在一起,所以程序员通常不应该依赖于一个头,包括另一个头。但是,在少数情况下,一个头保证包含另一个头,或者使某些函数可以在其他情况下需要包含另一个头。这种情况下是什么?
1 个解决方案
#1
33
This answer ignores C headers - both the <meow.h>
and <cmeow>
ones. Of the C++ library headers (all references are to N4659):
这个答案忽略了C页眉-都是 <喵。h> 和< cmeow >。的c++库头(所有引用都指向N4659):
<initializer_list>
is guaranteed to be included by:
-
<utility>
(§23.2.1 [utility.syn]) - < >效用(§23.2.1[utility.syn])
-
<string>
(§24.3.1 [string.syn]) - <字符串> (§24.3.1[string.syn])
-
<array>
(§26.3.2 [array.syn]) - < >数组(§26.3.2[array.syn])
-
<deque>
(§26.3.3 [deque.syn]) - <双端队列> (§26.3.3[deque.syn])
-
<forward_list>
(§26.3.4 [forward_list.syn]) - < forward_list >(§26.3.4[forward_list.syn])
-
<list>
(§26.3.5 [list.syn]) - <列表> (§26.3.5[list.syn])
-
<vector>
(§26.3.6 [vector.syn]) - <向量> (§26.3.6[vector.syn])
-
<map>
(§26.4.2 [associative.map.syn]) - < >地图(§26.4.2[associative.map.syn])
-
<set>
(§26.4.3 [associative.set.syn]) - <设置> (§26.4.3[associative.set.syn])
-
<unordered_map>
(§26.5.2 [unord.map.syn]) - < unordered_map >(§26.5.2[unord.map.syn])
-
<unordered_set>
(§26.5.3 [unord.set.syn]) - < unordered_set >(§26.5.3[unord.set.syn])
-
<queue>
(§26.6.2 [queue.syn]) - <队伍> (§26.6.2[queue.syn])
-
<stack>
(§26.6.3 [stack.syn]) - <堆栈> (§26.6.3[stack.syn])
-
<algorithm>
(§28.2 [algorithms.syn]) - <算法> (§28.2[algorithms.syn])
-
<random>
(§29.6.2 [rand.synopsis]) - <随机> (§29.6.2[rand.synopsis])
-
<valarray>
(§29.7.1 [valarray.syn]) - < valarray >(§29.7.1[valarray.syn])
-
<regex>
(§31.4 [re.syn]) - <正则表达式> (§31.4[re.syn])
<iostream>
is guaranteed to include <ios>
, <streambuf>
, <istream>
, and <ostream>
(§30.4.1 [iostream.syn]).
< iostream >是保证包括< ios >、< streambuf >、< istream >, <上ostream> (§30.4.1[iostream.syn])。
<ios>
is guaranteed to include <iosfwd>
(§30.5.1 [ios.syn]).
< ios >是保证包括< iosfwd >(§30.5.1[ios.syn])。
<bitset>
is guaranteed to include <string>
and <iosfwd>
(§23.9.1 [bitset.syn]).
< bitset >是保证包括 <字符串> 和< 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]).
*函数模板std::开始,std::最后,c++ 14 C - r -,和cr -版本,和c++ 17*函数模板std::大小、std::空和std::名义上的数据驻留在 <迭代器> ,但也可以如果下列标题包括: <数组> 、 <双端队列> 、< forward_list >、 <列表> 、 <地图> 、 <正则表达式> 、 <设置> 、 <字符串> 、< unordered_map >、< unordered_set >, <向量> (§27.7[迭代器。范围,§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]).
当包含
#1
33
This answer ignores C headers - both the <meow.h>
and <cmeow>
ones. Of the C++ library headers (all references are to N4659):
这个答案忽略了C页眉-都是 <喵。h> 和< cmeow >。的c++库头(所有引用都指向N4659):
<initializer_list>
is guaranteed to be included by:
-
<utility>
(§23.2.1 [utility.syn]) - < >效用(§23.2.1[utility.syn])
-
<string>
(§24.3.1 [string.syn]) - <字符串> (§24.3.1[string.syn])
-
<array>
(§26.3.2 [array.syn]) - < >数组(§26.3.2[array.syn])
-
<deque>
(§26.3.3 [deque.syn]) - <双端队列> (§26.3.3[deque.syn])
-
<forward_list>
(§26.3.4 [forward_list.syn]) - < forward_list >(§26.3.4[forward_list.syn])
-
<list>
(§26.3.5 [list.syn]) - <列表> (§26.3.5[list.syn])
-
<vector>
(§26.3.6 [vector.syn]) - <向量> (§26.3.6[vector.syn])
-
<map>
(§26.4.2 [associative.map.syn]) - < >地图(§26.4.2[associative.map.syn])
-
<set>
(§26.4.3 [associative.set.syn]) - <设置> (§26.4.3[associative.set.syn])
-
<unordered_map>
(§26.5.2 [unord.map.syn]) - < unordered_map >(§26.5.2[unord.map.syn])
-
<unordered_set>
(§26.5.3 [unord.set.syn]) - < unordered_set >(§26.5.3[unord.set.syn])
-
<queue>
(§26.6.2 [queue.syn]) - <队伍> (§26.6.2[queue.syn])
-
<stack>
(§26.6.3 [stack.syn]) - <堆栈> (§26.6.3[stack.syn])
-
<algorithm>
(§28.2 [algorithms.syn]) - <算法> (§28.2[algorithms.syn])
-
<random>
(§29.6.2 [rand.synopsis]) - <随机> (§29.6.2[rand.synopsis])
-
<valarray>
(§29.7.1 [valarray.syn]) - < valarray >(§29.7.1[valarray.syn])
-
<regex>
(§31.4 [re.syn]) - <正则表达式> (§31.4[re.syn])
<iostream>
is guaranteed to include <ios>
, <streambuf>
, <istream>
, and <ostream>
(§30.4.1 [iostream.syn]).
< iostream >是保证包括< ios >、< streambuf >、< istream >, <上ostream> (§30.4.1[iostream.syn])。
<ios>
is guaranteed to include <iosfwd>
(§30.5.1 [ios.syn]).
< ios >是保证包括< iosfwd >(§30.5.1[ios.syn])。
<bitset>
is guaranteed to include <string>
and <iosfwd>
(§23.9.1 [bitset.syn]).
< bitset >是保证包括 <字符串> 和< 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]).
*函数模板std::开始,std::最后,c++ 14 C - r -,和cr -版本,和c++ 17*函数模板std::大小、std::空和std::名义上的数据驻留在 <迭代器> ,但也可以如果下列标题包括: <数组> 、 <双端队列> 、< forward_list >、 <列表> 、 <地图> 、 <正则表达式> 、 <设置> 、 <字符串> 、< unordered_map >、< unordered_set >, <向量> (§27.7[迭代器。范围,§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]).
当包含