Rename overloaded `insert()` to `emplace()` and add overloaded versions for all possible lvalue/rvalue combinationsfor its arguments.

This commit is contained in:
Alberto Gonzalez 2020-04-15 16:22:22 +00:00
parent c479fdeb85
commit 5eb1f83d2d
No known key found for this signature in database
GPG Key ID: 8395A8BA109708B2
1 changed files with 31 additions and 1 deletions

View File

@ -465,7 +465,17 @@ public:
return std::pair<iterator, bool>(iterator(this, i), true);
}
std::pair<iterator, bool> insert(K const &key, T &&rvalue)
std::pair<iterator, bool> emplace(K const &key, T const &value)
{
int hash = do_hash(key);
int i = do_lookup(key, hash);
if (i >= 0)
return std::pair<iterator, bool>(iterator(this, i), false);
i = do_insert(std::make_pair(key, value), hash);
return std::pair<iterator, bool>(iterator(this, i), true);
}
std::pair<iterator, bool> emplace(K const &key, T &&rvalue)
{
int hash = do_hash(key);
int i = do_lookup(key, hash);
@ -475,6 +485,26 @@ public:
return std::pair<iterator, bool>(iterator(this, i), true);
}
std::pair<iterator, bool> emplace(K &&rkey, T const &value)
{
int hash = do_hash(rkey);
int i = do_lookup(rkey, hash);
if (i >= 0)
return std::pair<iterator, bool>(iterator(this, i), false);
i = do_insert(std::make_pair(std::forward<K>(rkey), value), hash);
return std::pair<iterator, bool>(iterator(this, i), true);
}
std::pair<iterator, bool> emplace(K &&rkey, T &&rvalue)
{
int hash = do_hash(rkey);
int i = do_lookup(rkey, hash);
if (i >= 0)
return std::pair<iterator, bool>(iterator(this, i), false);
i = do_insert(std::make_pair(std::forward<K>(rkey), std::forward<T>(rvalue)), hash);
return std::pair<iterator, bool>(iterator(this, i), true);
}
int erase(const K &key)
{
int hash = do_hash(key);