move semantics/perfect forwarding for hashtable keys
parent
48b8ba7522
commit
c5678238c3
|
@ -90,9 +90,9 @@ namespace detail {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
T &insert(octa::Size h, const U &key) {
|
T &insert(octa::Size h, U &&key) {
|
||||||
Chain *c = insert(h);
|
Chain *c = insert(h);
|
||||||
B::set_key(c->value, key);
|
B::set_key(c->value, octa::forward<U>(key));
|
||||||
return B::get_data(c->value);
|
return B::get_data(c->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
octa/map.h
10
octa/map.h
|
@ -26,9 +26,9 @@ namespace detail {
|
||||||
return e.second;
|
return e.second;
|
||||||
}
|
}
|
||||||
template<typename U>
|
template<typename U>
|
||||||
static inline void set_key(Element &e, const U &key) {
|
static inline void set_key(Element &e, U &&key) {
|
||||||
e.first.~K();
|
e.first.~K();
|
||||||
new ((K *)&e.first) K(key);
|
new ((K *)&e.first) K(octa::forward<U>(key));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,12 @@ public:
|
||||||
if (v) return *v;
|
if (v) return *v;
|
||||||
return p_table.insert(h, key);
|
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) {
|
void swap(Map &v) {
|
||||||
octa::swap(p_table, v.p_table);
|
octa::swap(p_table, v.p_table);
|
||||||
|
|
Loading…
Reference in New Issue