Skip to content

Commit 51eb683

Browse files
authored
Have constructor return a reference to the value_type (#39)
* Update `constructor` so that the call operator returns a pointer to the slot. * Return a refernce to the `value_type`
1 parent e5af25a commit 51eb683

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

include/gtl/phmap.hpp

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

2146-
// returns a pointer to the inserted value.
2147-
// beware that the returned pointer is stable only for `node` hash map or sets. When using
2148-
// a `flat` version, this pointer can be used immediately, but shouldn't be stored.
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.
21492149
template<class... Args>
2150-
slot_type* operator()(Args&&... args) const {
2150+
const auto& operator()(Args&&... args) const {
21512151
assert(*slot_);
21522152
PolicyTraits::construct(alloc_, *slot_, std::forward<Args>(args)...);
2153-
return *slot_;
2153+
return PolicyTraits::element(slot());
21542154
}
21552155

21562156
private:

0 commit comments

Comments
 (0)