为什么有序的std::map和有序的std::set没有被邀请进行transaction_safe
Why are ordered std::map and ordered std::set not invited to make transaction_safe?
众所周知,实验C++中有事务内存TS(ISO/IEC TS 19841:2015):将函数声明为transaction_safe就足够了吗?
而声明为transaction_safe
的operator[]
仅适用于容器:std::vector
、std::unordered_map
、std::unordered_multimap
、std::unordered_set
、std::unordered_multiset
、std::deque
-取自n4514:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4514.pdf
23.4关联容器[关联]
23.4.4类模板图【图】
23.4.4.1类别模板地图概述[map.overview]
在23.4.4.1[map.overview]中,将"transaction_safe"添加到声明中开始和结束成员函数的所有变体以及size、max_size和empty的声明。
但是为什么对于std::map
和std::set
没有operator[]
声明为transaction_safe
(但是对于unordered_map
/unordered_set
有)?
为什么要在std::map
和std::set
的begin
和end
成员函数的所有变体的声明中添加"transaction_safe"?
迭代器begin
和end
对于std::array
、std::vector
或std::list
是非常必要的,但对于关联阵列则不是。在关联数组中,需要查找或查找并修改函数:find
、at
、insert
、erase
和operator[]
。没有他们,这是没有意义的。
为什么有序的std::map和有序的std::set没有被邀请进行transaction_safe?
unordered_meow::operator[]
被指定为无条件事务安全是一个缺陷。
- 首先,
unordered_set
、unordered_multiset
和unordered_multimap
根本没有operator[]
unordered_map::operator[]
必须调用Hash
和Pred
,并可能分配内存和构造新的键值对;这些都不一定是交易安全的
相反,map::operator[]
的事务安全性是由添加到[container.requirements.general]:来管理的
除非无条件指定为事务安全,否则中的函数如果所有必需的操作都是交易安全。[注意:这包括对元素的操作类型,在
std::allocator_traits
和Compare
、Pred
或Hash
对象上,取决于各自的功能尾注]
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用一个考虑到std::map中键值的滚动或换行的键
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么 std::unique 不调用 std::sort?
- 使用std::函数映射对象方法
- 可组合的lambda/std::函数与std::可选