From 537bedbf38889d5946199a9bfc6e2e0df66503c5 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Fri, 15 Jan 2021 15:59:55 -0700 Subject: [PATCH] HashTable: Correctly pass args to set Problem: - Using regular functions rather than function templates results in the arguments not being deduced. This then requires the same function to be written multiple times and for `move` to be used rather than `forward`. Solution: - Collapse multiple function overloads to a single function template with a deduced argument. This allows the argument to be a forwarding reference and bind to either an l-value or r-value and forward the value. --- AK/HashTable.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/AK/HashTable.h b/AK/HashTable.h index b1cc8c0570..9f4aaf4e74 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -203,15 +203,16 @@ public: *this = HashTable(); } - HashSetResult set(T&& value) + template + HashSetResult set(U&& value) { auto& bucket = lookup_for_writing(value); if (bucket.used) { - (*bucket.slot()) = move(value); + (*bucket.slot()) = forward(value); return HashSetResult::ReplacedExistingEntry; } - new (bucket.slot()) T(move(value)); + new (bucket.slot()) T(forward(value)); bucket.used = true; if (bucket.deleted) { bucket.deleted = false; @@ -221,11 +222,6 @@ public: return HashSetResult::InsertedNewEntry; } - HashSetResult set(const T& value) - { - return set(T(value)); - } - template Iterator find(unsigned hash, Finder finder) {