[英]Is flat_map an STL container?
In the current draft of C++23s flat_map
design, the type flat_map::reference
is defined as pair<const key_type&, mapped_type&>
, ie it is not a reference to flat_map::value_type = pair<key_type, mapped_type>
.在当前的C++23s
flat_map
设计草案中,类型flat_map::reference
被定义为pair<const key_type&, mapped_type&>
,即不是对flat_map::value_type = pair<key_type, mapped_type>
的引用。 (This seems to be mandatory, since the keys and values are stored not as pairs, but in two separate containers.) Thus, the iterators must be some proxy-class. (这似乎是强制性的,因为键和值不是成对存储的,而是存储在两个单独的容器中。)因此,迭代器必须是某个代理类。
This makes me think: Is a flat_map
actually even an STL container, similar to std::vector<bool>
isn't one?这让我想到:
flat_map
实际上是一个 STL 容器,类似于std::vector<bool>
不是吗?
The standard defines what a "container" is in [container.reqmts].该标准定义了 [container.reqmts] 中的“容器”。 Among these requirements is :
这些要求包括:
typename X::reference
- Result:
T&
结果:
T&
So yes, std::flat_map
is not a container.所以是的,
std::flat_map
不是容器。
But it never claims to be;但它从未声称是; it is a "container adapter" :
它是一个“容器适配器” :
A
flat_map
is a container adaptor...flat_map
是容器适配器...
Note that like std::stack/queue/priority_queue
, std::flat_set/map
take container types as template parameters.请注意,与
std::stack/queue/priority_queue
一样, std::flat_set/map
将容器类型作为模板参数。
It should also be noted that, while they are not containers, they are ranges as defined by the C++20 range library's concepts.还应注意,虽然它们不是容器,但它们是由 C++20范围库的概念定义的范围。 The C++20 ranges concepts allow for proxy ranges where the
reference
type need not be a value_type&
. C++20 范围概念允许
reference
类型不必是value_type&
的代理范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.