First of all, I would like to emphasize that hash_map is not part of the C++ standard library, and there is no universal standard. What I said below are all based on C++11's unordered_map. Overloading the unordered_map operator in [] is defined as
mapped_type& operator[] ( const key_type& k );
mapped_type& operator[] ( key_type&& k );
As you can see, what is returned here is a reference, so there is no problem in accepting it by reference.
First of all, I would like to emphasize that
hash_map
is not part of the C++ standard library, and there is no universal standard. What I said below are all based on C++11'sunordered_map
.Overloading the
unordered_map
operator in[]
is defined asAs you can see, what is returned here is a reference, so there is no problem in accepting it by reference.