diff --git a/octa/internal/hashtable.h b/octa/internal/hashtable.h index 5f3e6cf..0ba58c0 100644 --- a/octa/internal/hashtable.h +++ b/octa/internal/hashtable.h @@ -90,9 +90,9 @@ namespace detail { } template - T &insert(octa::Size h, const U &key) { + T &insert(octa::Size h, U &&key) { Chain *c = insert(h); - B::set_key(c->value, key); + B::set_key(c->value, octa::forward(key)); return B::get_data(c->value); } diff --git a/octa/map.h b/octa/map.h index 6461d90..eff1709 100644 --- a/octa/map.h +++ b/octa/map.h @@ -26,9 +26,9 @@ namespace detail { return e.second; } template - static inline void set_key(Element &e, const U &key) { + static inline void set_key(Element &e, U &&key) { e.first.~K(); - new ((K *)&e.first) K(key); + new ((K *)&e.first) K(octa::forward(key)); } }; } @@ -85,6 +85,12 @@ public: if (v) return *v; return p_table.insert(h, key); } + T &operator[](K &&key) { + octa::Size h; + T *v = p_table.access_base(key, h); + if (v) return *v; + return p_table.insert(h, octa::move(key)); + } void swap(Map &v) { octa::swap(p_table, v.p_table);