C++ 如何将bimap中的两个或多个元素作为键

C++ 如何将bimap中的两个或多个元素作为键,c++,boost-bimap,C++,Boost Bimap,我想知道是否可以在bimap中插入两个或多个元素作为键。我有一个带有一个元素键的bimap的最小示例 #include <boost/bimap.hpp> #include <boost/bimap/multiset_of.hpp> #include <string> #include <iostream> int main() { typedef boost::bimap<boost::bimaps::set_of<int>

我想知道是否可以在
bimap
中插入两个或多个元素作为键。我有一个带有一个元素键的
bimap
的最小示例

#include <boost/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <string>
#include <iostream>

int main()
{
  typedef boost::bimap<boost::bimaps::set_of<int>,boost::bimaps::multiset_of<int> > bimap;
  bimap numbers;

  numbers.insert({1, 1});
  numbers.insert({2, 1});
  numbers.insert({3, 8});
  auto it = numbers.left.find(1);


  std::cout << it->first << ":" << it->second << std::endl;
}
#包括
#包括
#包括
#包括
int main()
{
typedef boost::bimap bimap;
bimap编号;
插入({1,1});
插入({2,1});
插入({3,8});
自动it=数字。左。查找(1);
std::cout首先一对int的类型为
(在C++11及更高版本中也是

typedef boost::bimap bimap;
bimap编号;
插入({1,1,5});
插入({2,{1,1}});

注意插页中额外的{}对不起,我觉得自己很笨,但是你说的“两个元素”是什么意思?你不是明目张胆地在地图中插入了三个元素吗?@KerrekSB噢!!如果我没有把它放好,很抱歉。我的意思是不,等等,请让你的问题独立起来。我不想为了意义而大惊小怪。我在我的日常工作中已经这样做了。@KerrekSB我想有一个唯一的钥匙,我有
boost::bimaps::set\u of
o我的
boost::bimaps::multiset_of
的另一个键(严格来说不是唯一的)。我想知道我是否可以再输入一个整数,比如
boost::bimaps::multiset_of
谢谢你的回答。我可以使用迭代器搜索任何东西,但如何使用
at(1)或at(2)来获取键及其值
从bimap的哪一侧开始?您可以使用例如
数字进行搜索。右。查找({1,1});
以获取2。我不想搜索。我知道我的键在那里,我想从左侧搜索一些东西,如
数字。左。at(1)
或从右在给定的示例中,您从中得到一个
std::pair
,值为
1,5
。如果这不是真的,我不知道您想要什么。
numbers.left.at(1)
应该给出
1,5
numbers.right.at(1,5)
是1
typedef boost::bimap<boost::bimaps::set_of<int>,boost::bimaps::multiset_of<int, int > > bimap;
bimap numbers;
numbers.insert({1, 1, 5});
numbers.insert({2, 1, 1});
typedef boost::bimap<boost::bimaps::set_of<int>,boost::bimaps::multiset_of<std::pair<int, int > > > bimap;
bimap numbers;
numbers.insert({1, {1, 5}});
numbers.insert({2, {1, 1}});