C ++ std :: map命名需求分配器感知容器 [英] C++ std::map named requirements allocator-aware container
问题描述
当前,我正在尝试将一些C ++的命名需求转换为C ++ 20概念( https://godbolt.org/z/EdY5d6319 仍然是WIP!).但是,我遇到了一个问题.
Currently I'm trying to convert some of C++'s named requirements to C++20 concepts (https://godbolt.org/z/EdY5d6319 still highly WIP!). However, I stumpled upon a problem.
给出最终的C ++ 20工作草案(http://open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4861.pdf ):
Given the final C++20 working draft (http://open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4861.pdf):
- 第790页:对可识别分配器的容器的要求:
给定具有value_type T的分配器感知容器X,表达式a == t
其中a
表示类型X和t
的非常量左值类型X的左值或常量值是必需的.
前提条件:T是Cpp17CopyInsertable,可以插入X和 Cpp17CopyAssignable 中.
->因此,X :: value_type
必须是CopyAssignable. - 第699页:
is_copy_assignable
:
对于可引用的类型T,结果与is_assignable_v< T& ;,常量T&
,否则为false
." - 第849页:
std :: map
:
地图满足容器,可逆容器(22.2),关联容器的所有要求.容器(22.2.6)和可识别分配器的容器(表76)."
- page 790: requirements for an allocator-aware container:
Given an allocator-aware container X with value_type T the expressiona == t
wherea
denotes a non-const lvalue of type X andt
an lvalue or const rvalue of type X is required.
Preconditions: T is Cpp17CopyInsertable into X and Cpp17CopyAssignable.
-> Therefore,X::value_type
must be CopyAssignable. - page 699:
is_copy_assignable
:
"For a referenceable type T, the same result asis_assignable_v<T&, const T&>
, otherwisefalse
." - page 849:
std::map
:
"A map meets all of the requirements of a container, of a reversible container (22.2), of an associative container (22.2.6), and of an allocator-aware container (Table 76)."
因此 std :: map< Key,T>
满足可识别分配器的容器的要求.因此, std :: map< Key,T> :: value_type
必须是CopyAssignable.但是, std :: map< Key,T> :: value_type
定义为 std :: pair< const Key,T>
,不是由于 Key
成为 const
,因此strong> CopyAssignable.因此, std :: map
不满足可识别分配器的容器要求,这与标准草稿中的第849页相矛盾.
So std::map<Key, T>
meets the requirements of an allocator-aware container. Therefore, std::map<Key, T>::value_type
must be CopyAssignable.
However, std::map<Key, T>::value_type
is defined as std::pair<const Key, T>
, which is not CopyAssignable due to Key
beeing const
.
Therefore, std::map
does not meet the allocator-aware container requirements, which contradicts page 849 in the standard draft.
我在这里想念什么?
推荐答案
在 除 The associative containers meet all the requirements of Allocator-aware containers, except that for 这篇关于C ++ std :: map命名需求分配器感知容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! map
和 multimap
之外,关联容器满足分配器感知容器的所有要求,而这些要求放在 value_type
中表76 适用于 key_type
和 mapped_type
.[注意:例如,在某些情况下,即使关联的 value_type
, pair< const key_type,mapped_type>
不是 Cpp17CopyAssignable
.—尾注]
map
and multimap
, the requirements placed on value_type
in Table 76 apply instead to key_type
and mapped_type
. [ Note: For example, in some cases key_type
and mapped_type
are required to be Cpp17CopyAssignable
even though the associated value_type
, pair<const key_type, mapped_type>
, is not Cpp17CopyAssignable
. — end note ]