C++ 是否有可能覆盖;查找“;及;抹去;boost::bimap::bimap.left的方法?怎么做?

C++ 是否有可能覆盖;查找“;及;抹去;boost::bimap::bimap.left的方法?怎么做?,c++,key-value,keyvaluepair,bimap,boost-bimap,C++,Key Value,Keyvaluepair,Bimap,Boost Bimap,我有以下建议: struct foo_and_number_helper { std::string foo; uint64_t number; }; struct foo_and_number {}; struct bar {}; using my_bimap = boost::bimaps::bimap< boost::bimaps::unordered_set_of<boost::bimaps::tagged<foo_and_number_helper, f

我有以下建议:

struct foo_and_number_helper {
  std::string foo;
  uint64_t number;
};
struct foo_and_number {};
struct bar {};

using my_bimap = boost::bimaps::bimap<
  boost::bimaps::unordered_set_of<boost::bimaps::tagged<foo_and_number_helper, foo_and_number>>, 
  boost::bimaps::multiset_of<boost::bimaps::tagged<std::string, bar>>
>;

my_bimap instance;
struct foo\u和\u number\u助手{
std::字符串foo;
uint64_t编号;
};
结构foo_和_数{};
结构条{};
使用my_bimap=boost::bimap::bimap<
boost::bimap::无序的,
boost::bimaps::多组
>;
我的bimap实例;
我希望能够像这样调用find和erase方法:
instance.left.find(“foo”)
而不是
instance.left.find({“foo”,1})

instance.left.erase(“foo”)
而不是
instance.left.erase({“foo”,1})

对于从左侧调用的find和erase方法,我只想使用“foo_和_number_helper”的“foo”部分,而不是这两个部分。如何做到这一点?我试着阅读bimap实现,但仍然很难做到

我已经问了更广泛的问题: 从注释中,我必须覆盖
操作符,我会选择这里的
boost::bimap

namespace bmi = boost::multi_index;

struct ElementType { 
  std::string foo; 
  std::string bar;
  uint64_t number; 
}

using my_bimap = boost::multi_index_container<
  ElementType,
  bmi::indexed_by<
    bmi::unordered_unique<
      bmi::tagged<struct Foo>, 
      bmi::member<ElementType, std::string, &ElementType::foo>
    >,
    bmi::ordered<
      bmi::tagged<struct Bar>, 
      bmi::member<ElementType, std::string, &ElementType::bar>
    >,
    // and others like
    bmi::sequenced<
      bmi::tagged<struct InsertionOrder>
    >
  >
>;
namespace bmi=boost::multi_index;
结构元素类型{
std::字符串foo;
字符串条;
uint64_t编号;
}
使用my_bimap=boost::multi_index_容器<
元素类型,
bmi::按索引索引<
bmi::无序_唯一<
bmi::标记,
bmi::成员
>,
有序的<
bmi::标记,
bmi::成员
>,
//其他人喜欢
bmi::测序<
bmi::标记
>
>
>;
然后你会像这样使用它

my_bimap instance;

instance.get<Foo>().find("foo");
instance.get<Bar>().erase("bar");
std::cout << instance.get<InsertionOrder>()[10].foo;
my_bimap实例;
get().find(“foo”);
get().erase(“bar”);

std::cout所以我按照@Caleth的答案进行了调整:

#include <boost/multi_index/hashed_index.hpp>
#include <boost/bimap/bimap.hpp>

using namespace std;

struct ElementType { 
  string foo; 
  string bar;
  uint64_t number; 
};

using namespace boost::multi_index;

using my_bimap = multi_index_container<
  ElementType,
  indexed_by<
    hashed_unique<member<ElementType, string, &ElementType::foo>>,
    ordered_non_unique<member<ElementType, string, &ElementType::bar>>
  >
>;

int main() {
  my_bimap instance;

  instance.insert({"foo", "bar", 0});
  instance.insert({"bar", "bar", 1});

  cout << instance.get<0>().find("bar")->foo << endl;
  cout << instance.get<0>().find("bar")->bar << endl;
  cout << instance.get<0>().find("bar")->number << endl;
  auto range = instance.get<1>().equal_range("bar");
  for (auto it = range.first; it != range.second; ++it) {
    cout << it->foo << endl;
    cout << it->number << endl;
  }

  cin.sync();
  cin.ignore();
}

是的,它没有回答我的问题,但我想我实现了我想要的

阅读之后,也许我会继续阅读。谢谢你的回答!我已经花了将近一天的时间研究如何做。我忘了提到它必须节省空间(可能是,foo、bar和number只存储一次),而且速度快(将包含数百万个值)。我猜foo、bar和number周围的空间很小,速度也快不了多少。我说得对吗?我认为
boost::bimap
boost::multi_index_container
的一个特例,或者至少在这方面是可以实现的。忽略已排序的
索引(我添加该索引是为了说明您可以拥有任意数量的索引),我希望它们是相同的数据结构:一个包含4个指针的节点和一个
元素类型
(或等效元组),排列为两个(不同的)平衡树。您向我展示了如何使用它,但它需要完全重写!:它在语法上完全不正确。
bar
bar
1
foo
0
bar
1