|
Boost Users : |
Subject: Re: [Boost-users] [Unordered] [Multi-Index] Set lookup from something else than key_type
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2009-09-02 16:27:08
On Wed, Sep 2, 2009 at 2:17 PM, Joaquin M Lopez Munoz<joaquin_at_[hidden]> wrote:
> [...] The net effect is that
> we pass from one implicit conversion when invoking
> find() to multiple implicit conversions inside find()
> code.
Ah yes, that's unfortunate. Thanks for making that clear.
A "simple" solution is to not overload, and rename the find() overload
into find_compatible_key(another_type) to remove this possibility, while
not having to provide explicitly the hash/pred to find(ckey,hash,pred):
typedef boost::unordered_set<
my_type, hash_by_uid<my_type>, compare_by_uid<my_type>
> my_type_set;
my_type::uid_t some_uid = ...;
const my_type_set& set = ...;
my_type_set::iterator found1 = set.find(
some_uid, my_type_set::hasher(), my_type_set::key_equal()
);
my_type_set::iterator found2 = set.find_compatible_key(some_uid);
assert(found1 == found2);
The 1-arg find_compatible_key(compatible_key_t) assumes appropriate
overloads for compatible_key_t in hash/pred, and delegates to the containers
hash/pred and the 3-arg find(). Can even be a free template function
in fact. --DD
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net