7

See https://en.cppreference.com/w/cpp/io/basic_ios/operator_bool and https://en.cppreference.com/w/cpp/io/basic_ios/operator!.

I think that operator! is redundant because of the user-defined operator bool.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
feitao
  • 103
  • 3
  • 3
    There's a bit of history here. It wasn't always `explicit operator bool`(since the language didn't have explicit conversion ops), see [this Q&A](https://stackoverflow.com/q/3222131/817643). But in retrospect, *now*, you are spot on, it is indeed redundant. Just that to remove it, someone has to bring it up before a committee, and that isn't a fast enough process to warrant just this small change. Might happen in a future general library tidy-up paper. – StoryTeller - Unslander Monica Mar 12 '23 at 10:52
  • @StoryTeller-UnslanderMonica: And when someone brings it up to a committee, someone else will point out that an imaginary third party might be using `operator!` by name, and so removing it would be a breaking change for no benefit. – John Zwinck Mar 12 '23 at 15:16
  • @JohnZwinck- That doesn't seem to be the state of mind as of recently. `operator<=>` replaced many existing operator overloads in the standard library recently, and they were removed entirely along with the replacement getting added. – StoryTeller - Unslander Monica Mar 12 '23 at 15:20
  • @StoryTeller-UnslanderMonica "`explicit operator bool` _(since the language didn't have explicit conversion ops),_" AFAIK `explicit operator bool` is not an "explicit conversion", it's just `explicit operator bool`, the one and only! – curiousguy Mar 12 '23 at 21:59

0 Answers0