I have the following code:
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/unordered_multiset_of.hpp>
#include <string>
using namespace boost::bimaps;
using namespace boost;
struct Example
{
uint64_t id;
};
struct ExampleHash
{
uint64_t operator()(const Example& item) const
{
return item.id;
}
uint64_t operator()(const uint64_t item) const
{
return item;
}
};
struct ExampleEq
{
bool operator()(const Example& l, const Example& r) const
{
return l.id == r.id;
}
bool operator()(const uint64_t l, const Example& r) const
{
return l == r.id;
}
bool operator()(const Example& l, const uint64_t r) const
{
return operator()(r, l);
}
};
using BM = bimaps::bimap<
unordered_multiset_of<std::string>,
unordered_multiset_of<Example, ExampleHash, ExampleEq>
>;
int main() {
BM bm;
bm.insert(BM::value_type("First", Example{1}));
auto it = bm.right.find(1u);
return 0;
}
According to boost documentation
template< class CompatibleKey >
iterator find(const CompatibleKey & x);
A type CompatibleKey is said to be a compatible key of (Hash, Pred) if (CompatibleKey, Hash, Pred) is a compatible extension of (Hash, Pred). This implies that Hash and Pred accept arguments of type CompatibleKey, which usually means they have several overloads of their corresponding operator() member functions.
So I thought that auto it = bm.right.find(1u);
will work. Unfortunately this generates an compilation error:
error: no match for call to (boost::bimaps::container_adaptor::detail::key_to_base_identity<Example, const Example>) (const long unsigned int&)
My question is if it is even possible to use CompatibleKey of a diffrent type than bimap key type? I have already tried to go over the boost headers, unfortunately the implmentation is too complicated for me to comprehend what is going on.