C++ Logo

std-proposals

Advanced search

Re: [std-proposals] D3666R0 Bit-precise integers

From: Jan Schultke <janschultke_at_[hidden]>
Date: Wed, 3 Sep 2025 05:36:12 +0200
+1 to explicit conversions

I have written plenty of code that performs operations on bool in
arithmetic over the years, and I still think the feature does overall
more harm than good. Having this conversion be implicit just makes it
easier to write category errors, and having an explicit conversion via
int(x) would be simple and concise.

I have published
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3765r0.html
which at least deprecates implicit conversions from bool to character
types. Other bool-to-X conversions are probably too common to ever be
removed from the language now.

On Tue, 2 Sept 2025 at 23:21, David Brown via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
>
>
> On 02/09/2025 20:38, Sebastian Wittmeier via Std-Proposals wrote:
> > Disallowing additions of (implicitly int-converted) bool values is a bad
> > idea.
> >
> > A huge advantage of C++ is the long compatibility for low-level
> > algorithms. They can just be inserted and compiled.
> > bool a = true;
> > bool b = true;
> > bool c = false;
> > if (a + b + c >= 2) ...; // test whether at least two booleans are true
> >
>
> I agree that suitability for low-level work is a huge advantage of C++.
> But that does not mean it needs to have implicit conversions - explicit
> conversions would do the job fine :
>
> if (int(a) + int(b) + int(c) >= 2) ....
>
> It is very rare IME that you need to add bools - having an explicit cast
> would not be a problem.
>
> > We should create the std::strong_bool instead or use some bool profile.
> >
> >
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-09-03 03:36:30