C++ Logo

std-proposals

Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 2 Sep 2025 23:59:00 +0200
Yes, it could have worked with explicit casts to int, if done so from the beginning. But those are really basic math operations, which have worked for decades without change on various platforms from small embedded systems to PCs to GPUs to specify algorithms. There is lots of complex code out there using those implicit conversions from bool to 0 and 1. I do not think it is feasible to disallow those now (at least in general, a safety profile could be more acceptable).   Other code: bool b0, b1, b2; // bits int number = b2 * 4 + b1 * 2 + b0;   -----Ursprüngliche Nachricht----- Von:David Brown via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Di 02.09.2025 23:21 Betreff:Re: [std-proposals] D3666R0 Bit-precise integers An:std-proposals_at_[hidden]; CC:David Brown <david.brown_at_[hidden]>; 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-02 22:10:12