berserker's blog

By berserker, history, 5 years ago, In English

Using lambda expression inside sort.

GNUC++14 Runtime error

GNUC++11 AC

Using comp function instead of lambda.

GNUC++14 Runtime error

GNUC++11 AC

Clang++17 AC

I don't understand why I am getting undefined behaviour. I have used only basic constructs.

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

»
5 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Use > instead of >= in comparator.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I had a similar error which got fixed by this method. Can you please explain what is the reason for the same?

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Because that's how it is defined

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it +2 Vote: I do not like it

        Please, don't reply with useless information. That's annoying

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          What do you mean? That's just how it is defined, that's how they made it.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

When you compose a cmp function bool cmp(const T &t1, const T &t2), it should return false when the two parameters t1, t2 have the same value. This detail makes sense and just remember it.