Why no transparent C++1x std::map::at?

天大地大妈咪最大 提交于 2019-12-23 07:57:46

问题


Is there a reason for missing transparent (template <class K> at(K&& key);) in std::map?


回答1:


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.



来源:https://stackoverflow.com/questions/40767213/why-no-transparent-c1x-stdmapat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!