bobah bobah - 16 days ago 10
C++ Question

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

Is there a reason for missing transparent (

template <class K> at(K&& key);
) in
std::map
?

Answer

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.