I've always found C++'s "trend" of handling normal or non-exceptional system errors with exceptions lackluster (and I'm being charitable). Overall trimming things down to (basically) passing around a couple integers and telling the user to check their manual is much better, much less error prone, and much more efficient and deterministic.

you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 1 year ago (7 children)

Same, I also like giving this the [[nodiscard]] attribute if I want to make sure that it's not ignored.

  • source
  • parent
  • hideshow 7 child comments
  • [–] 4 points 1 year ago (6 children)

    -Wunused-result is good practice in general

  • source
  • parent
  • hideshow 6 child comments
  • [–] 2 points 1 year ago (5 children)

    I'm mixed on this one, because sometimes you'll want to call a function for its side effects without caring about the return value. E. g. container methods returning an iterator that shows you where the side effect took place.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 3 points 1 year ago (4 children)

    Right, so just cast the returned value to void: (void)function();

  • source
  • parent
  • hideshow 4 child comments
  • [–] 3 points 1 year ago (2 children)

    The new C++ way is

    std::ignore = function();
    
  • source
  • parent
  • hideshow 2 child comments
  • [–] [S] 0 points 1 year ago

    First: it's not new, it's been around since C++03.

    Second... it's not even that great. It's more characters to type and you have to deal with stds and colons. (void) is a classic and works everywhere.

    But hey, at least it's not static_cast<void>(...).

  • source
  • parent