C++ Logo

std-proposals

Advanced search

Re: [std-proposals] comparison between pointers and bool

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 12 May 2025 10:32:36 -0400
On Mon, May 12, 2025 at 10:21 AM Tymi via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> I think pointer == bool should be permitted
> For instance
> `if (myPointer == false) throw nullptr;`
>
> Tymi.

OK: what does that test *mean*? How can a pointer be "false"?

If you explicitly use a boolean literal in the condition, there's
basically no reason to type that instead of `nullptr`. `myPointer ==
nullptr` leaves absolutely no doubt about what your code means.

And if you have some boolean variable and you're testing it against a
pointer... why? When would that ever come up? Would this be in some
template code somewhere? Can you give an example where this is
necessary?

Received on 2025-05-12 14:32:48