Open GoogleCodeExporter opened 9 years ago
As an alternative, would it be acceptable to add "empty type" and maybe even
"deleted type" class template parameters? Those types must be pairs that
potentially differ from `value_type` in their second field. This is fine, since
we never access the `mapped_type` of deleted or empty elements, so any type
with the same size and alignment requirements would do. We could even leave the
`mapped_type` memory uninitialized for those values, potentially improving
deletion perf.
This approach has a lot of advantages, such as:
- The user can make the class behave just like std::unordered_map by specifying those template extra parameters
- Non-default-constructible types can be transparently supported in C++11 (since it has good memory layout introspection).
- Prior to C++11, it's pretty simple for folks to make this work for non-default-constructible types, e.g. like this:
struct EmptyValueType : std:pair<Key, Data> {
EmptyValueType() : std::pair<Key, Data>(makeEmptyKey(), makeEmptyValue()) {}
};
google::dense_hash_map<Key, Data, HashFcn, EqualKey, Alloc, EmptyValueType> h;
PS Thanks to John Fremlin for the helpful discussion that led to this
counter-proposal.
Original comment by snarkmas...@gmail.com
on 22 Feb 2015 at 8:38
Original issue reported on code.google.com by
snarkmas...@gmail.com
on 19 Feb 2015 at 3:55Attachments: