У меня есть следующий код:
#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;
}
Согласно форсированной документации
template< class CompatibleKey >
iterator find(const CompatibleKey & x);
Тип CompatibleKey называется совместимым ключом (Hash, Pred), если (CompatibleKey, Hash, Pred) является совместимым расширением (Hash, Pred). Это подразумевает, что Hash и Pred принимают аргументы типа CompatibleKey, что обычно означает, что они имеют несколько перегрузок своих соответствующих функций-членов operator ().
Так что я думал, что auto it = bm.right.find(1u);
будет работать. К сожалению, это приводит к ошибке компиляции:
error: no match for call to (boost::bimaps::container_adaptor::detail::key_to_base_identity<Example, const Example>) (const long unsigned int&)
У меня вопрос: возможно ли использовать CompatibleKey другого типа, чем тип ключа bimap? Я уже пытался обойти заголовки наддува, к сожалению, реализация слишком сложна для меня, чтобы понять, что происходит.