Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This was the original sort function (it was meant to force "last" to be first on the list after the sort which obviously violated the requirement):

  std::sort(entries.begin(), entries.end(), [&last] (const auto &a, const auto &b) {
    if (last && last->getID() == a.id) {
      return true;
    }

    return a.time < b.time;
  });


Interesting… I’m sure you resolved this. But the textbook solution is:

1. std::find last

2. std::iter_swap(first, found)

3. std::sort(front + 1, back)




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: