From a74bdc109c1d66fc1772469d237854d56c129da6 Mon Sep 17 00:00:00 2001 From: Sangjin Han Date: Mon, 27 Aug 2018 10:28:25 -0700 Subject: [PATCH] cuckoo_map: allow template argument deduction The forwarding reference `VV&&` cannot be directly deduced from a braced-init-list function parameter. This limitation makes `c.Insert(key, {2, 3, 4});` fail, although it looks completely benign (C++ standard 14.8.2.5 (5.6)). Instead one must specify the type of the value like `c.Insert>(key, {2, 3, 4});`. It is unnecessarily verbose since the value type is already known to be `V`, but the compiler does not know about the relationship between `V` and `VV`. This patch replaces the use of forwarding reference `VV&&` with two seperate copy/move references. It does make the code a bit more verbose on the library side, but not on the user side. --- core/utils/cuckoo_map.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/utils/cuckoo_map.h b/core/utils/cuckoo_map.h index a0fb4b496..c855b93de 100644 --- a/core/utils/cuckoo_map.h +++ b/core/utils/cuckoo_map.h @@ -210,10 +210,14 @@ class CuckooMap { // On success returns a pointer to the inserted entry, nullptr otherwise. // NOTE: when Insert() returns nullptr, the copy/move constructor of `V` may // not be called. - template - Entry* Insert(const K& key, VV&& value, const H& hasher = H(), + Entry* Insert(const K& key, const V& value, const H& hasher = H(), + const E& eq = E()) { + return DoEmplace(key, hasher, eq, value); + } + + Entry* Insert(const K& key, V&& value, const H& hasher = H(), const E& eq = E()) { - return DoEmplace(key, hasher, eq, std::forward(value)); + return DoEmplace(key, hasher, eq, std::move(value)); } // Emplace/update-in-place a key value pair