我有一个像这样的无序 bimap:
using SymPressMap =
boost::bimap<boost::bimaps::unordered_set_of<sym>,
boost::bimaps::unordered_set_of<Press>>;
这基本上是“sym”和“Press”之间的双射。我想循环“Presses”的子集,如图所示:bimap state before and after
这是使用 std::unordered_map 编译但使用 bimap 失败的算法:
void Layout::cycle(SymVector syms) {
assert(syms.size() >= 2);
for (auto it = syms.rbegin(); it != syms.rend() - 1; it++) {
std::swap(sympressmap.left.at(*it), sympressmap.left.at(*(it + 1)));
}
}
基本思想是连续交换相邻的(就“syms”而言)元素。但我收到了这个错误:
Error C2678 binary '=': no operator found which takes a left-hand operand of type '_Ty' (or there is no acceptable conversion)
KeyboardOptimizer c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\utility 68
所以,问题是如何交换bimap中的两个元素?.
UPD:擦除插入版本感谢 John Zwinck,它编译
void Layout::cycle(SymVector syms) {
assert(syms.size() >= 2);
Press plast = pressmap.left.at(*syms.rbegin());
pressmap.left.erase(*syms.rbegin());
for (auto it = syms.rbegin() + 1; it != syms.rend(); it++) {
auto p = pressmap.left.at(*it);
pressmap.left.erase(*it);
pressmap.left.insert(SymPressMap::left_value_type(*(it - 1), p));
}
pressmap.left.insert(SymPressMap::left_value_type(*syms.begin(), plast));
}