Hacker News new | past | comments | ask | show | jobs | submit login

More like:

  switch (e) {
    case A:
      foo(); break;
    case B:
      bar(); break;
  }
  std::unreachable();
instead of:

  switch (e) {
    case A:
      foo(); break;
    case B:
      bar(); break;
    default:
      std::unreachable();
  }
The former is more likely to produce a warning if there is an enumeration C that you forgot to handle, or you added an enumeration C and missed a switch-case to update.

edit:

duh, it's supposed to be returns here instead of breaks.




But then all case branches hit the std::unreachable. How can that work in practice?


I think it's supposed to be a return not a break.


yeah, thanks! I added an edit.


This is so funny that you have just demonstrated how stupid this construction is in practice by making a mistake.




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

Search: