My question is slightly different from this one.
There is an unordered_set with TWO elements. I'd like to operate the two elements ''simultaneously'' like this:
unordered_set<vector<bool>> st;
st.insert(vector<bool>(100,true));
st.insert(vector<bool>(100,false));
// vector<bool> temp_v(100,true);
// temp_v[3] = false;
// st.insert(move(temp_v));
if (st.size()!=2) return;
for (int i=0; i<100; i++)
cout << (st.begin()->at(i)) ^ (st.rbegin()->at(i)) << endl;
However, unordered_set
has no member function rbegin()
. I know I can use an iterator pointing to u_s::begin()
and advance it by one. Is there any more "elegant" way to do that?
-------------------------------------Solution------------------------------------------
Inspired by @YSC, an elegant
way to achieve the purpose is:
auto & e1 = *begin(st);
auto & e2 = *(++begin(st));
for (int i=0; i<100; i++) cout << e1[i] ^ e2[i] << endl;
which, might rely on #include <algorithm>
, is almost the same as the two-iterator solution.