From: Alberto Gonzalez Date: Wed, 15 Apr 2020 16:22:22 +0000 (+0000) Subject: Rename overloaded `insert()` to `emplace()` and add overloaded versions for all possi... X-Git-Tag: working-ls180~633^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5eb1f83d2d8da1f5390ed1a2658793a4e25809ba;p=yosys.git Rename overloaded `insert()` to `emplace()` and add overloaded versions for all possible lvalue/rvalue combinationsfor its arguments. --- diff --git a/kernel/hashlib.h b/kernel/hashlib.h index f15a9d611..996bda38e 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -465,7 +465,17 @@ public: return std::pair(iterator(this, i), true); } - std::pair insert(K const &key, T &&rvalue) + std::pair 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(this, i), false); + i = do_insert(std::make_pair(key, value), hash); + return std::pair(iterator(this, i), true); + } + + std::pair 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(this, i), true); } + std::pair emplace(K &&rkey, T const &value) + { + int hash = do_hash(rkey); + int i = do_lookup(rkey, hash); + if (i >= 0) + return std::pair(iterator(this, i), false); + i = do_insert(std::make_pair(std::forward(rkey), value), hash); + return std::pair(iterator(this, i), true); + } + + std::pair emplace(K &&rkey, T &&rvalue) + { + int hash = do_hash(rkey); + int i = do_lookup(rkey, hash); + if (i >= 0) + return std::pair(iterator(this, i), false); + i = do_insert(std::make_pair(std::forward(rkey), std::forward(rvalue)), hash); + return std::pair(iterator(this, i), true); + } + int erase(const K &key) { int hash = do_hash(key);