I have an unordered bimap like this:
using SymPressMap =
boost::bimap<boost::bimaps::unordered_set_of<sym>,
boost::bimaps::unordered_set_of<Press>>;
Which is basically a bijection between "sym" and "Press". I want to cycle the subset of "Presses", like shown on the picture:bimap state before and after
Here is the algorithm which compiles with std::unordered_map but fails with 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)));
}
}
The basic idea is to consecutively swap adjacent (in terms of "syms") elements. But I'm getting this error:
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
So, the question is How to swap two elements in bimap?.
UPD: erase-insert version thanks to John Zwinck, which compiles
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));
}