Блог пользователя fugazi

Автор fugazi, история, 5 лет назад, По-английски

I am getting a very strange bug in my code for today's round problems B1, 2.

At a moment, I'm having a set of pairs.

[s]: {(1, 1), (1, 4), (1, 5), (1, 9), (1, 10), (2, 2), (2, 7)}

Then I'm accessing the last and second last element. (line 51-54 in mycode)

it = s.rbegin();  // prints *it = (2, 7)
it--; 
// prints *it = (1, 10)

But for some weird reason it jumps off (2, 2) and I'm unable to figure out why.

Any help will be appreciated.

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится +20 Проголосовать: не нравится

Since it is a reverse iterator, it++ should yield the second last element instead, and it-- will make it invalid, and dereferencing that is UB.