问题
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