为什么没有透明的C ++ 1x std :: map :: at? [英] Why no transparent C++1x std::map::at?
问题描述
是否存在丢失std::map
中的透明(template <class K> at(K&& key);
)的原因?
Is there a reason for missing transparent (template <class K> at(K&& key);
) in std::map
?
推荐答案
我的猜测是std::map::at()
必须是std::map::operator[]()
的边界检查"版本.提供std::map::operator[]()
的透明版本对std::map::key_type
和查询键类型K
施加了附加要求-如果查询键不在地图中,则必须将其插入(具有默认构造值),这意味着std::map::key_type
必须可以从查询键类型构造.
My guess is that std::map::at()
must be a "bounds-checked" version of std::map::operator[]()
. Providing a transparent version of std::map::operator[]()
imposes an additional requirement on std::map::key_type
and the query key type K
- if the query key is not in the map, it must be inserted (with default constructed value), which means that std::map::key_type
must be constructible from the the query key type.
这篇关于为什么没有透明的C ++ 1x std :: map :: at?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!