为什么没有透明的C ++ 1x std :: map :: at? [英] Why no transparent C++1x std::map::at?

查看:87
本文介绍了为什么没有透明的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆