Subject: [boost] [intrusive] advanced lookup/insertion suggestion
From: Rei Thiessen (rei.thiessen_at_[hidden])
Date: 2012-02-14 18:27:43
Something that has bothered me with the advanced lookup and insertion
functions is that I have to specify the hash/equality functors at every
If we don't consistently use the same (key_hash,key_equality) pair for a
given (element_type,key_type) pair,
the container invariant will likely be broken.
Thus, I think it's very un-"C++ like" to have to specify these two types
at every invocation site.
Assuming that we don't want to embed (key_type,key_hash,key_equality)
directly into the type of a container,
the library could use a type operator to automatically deduce the
appropriate hash/equality functions given an element/key type pair at the
find/insert member function instantiation point:
template<typename ElementType, typename KeyType>
// different name to avoid overload confusion.
// instantiation succeeds only when
// element_key_info is properly specialized
iterator unordered_set::find_key( KeyType const& k )
typedef key_hash hash_type;
typedef key_equality equality_type;
c.insert( e );
... = c.find_key( k );
These new signatures do not allow non-default-constructible hash/equality
functors, but the original signatures that do are still available.
I think this makes the code simpler and safer in exchange for some
additional type declarations.
Would this be a worthwhile addition to the intrusive associative
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk