Skip to content

Commit 0205f2f

Browse files
committed
Return a refernce to the value_type
1 parent 1c8a6e4 commit 0205f2f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

include/gtl/phmap.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,12 +2143,14 @@ class raw_hash_set {
21432143
return *slot_;
21442144
}
21452145

2146-
// returns a pointer to the inserted value
2146+
// returns a reference to the inserted `value_type`.
2147+
// beware that the returned reference is stable only for `node` hash map or sets. When using
2148+
// a `flat` version, this reference can be used immediately, but we shouldn't store a pointer to it.
21472149
template<class... Args>
2148-
slot_type* operator()(Args&&... args) const {
2150+
const auto& operator()(Args&&... args) const {
21492151
assert(*slot_);
21502152
PolicyTraits::construct(alloc_, *slot_, std::forward<Args>(args)...);
2151-
return *slot_;
2153+
return PolicyTraits::element(slot());
21522154
}
21532155

21542156
private:

0 commit comments

Comments
 (0)