fugazi's blog

By fugazi, history, 6 years ago, In English

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.

  • Vote: I like it
  • +6
  • Vote: I do not like it

»
6 years ago, # |
Rev. 2   Vote: I like it +20 Vote: I do not like it

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.