This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
operator[](const K& k) { Hashtable* h = static_cast<Hashtable*>(this); - typename Hashtable::iterator it = - h->insert(std::make_pair(k, mapped_type())).first; + + typename Hashtable::iterator it = h->find(k); + if (it == h->end()) + it = h->insert(std::make_pair(k, mapped_type())).first; return it->second; } };
I guess if it was ok to have a bit of extra overhead when using operator[] for only inserting in std::map than it would be fine here as well.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |