C++ Logo

std-proposals

Advanced search

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

From: Bjorn Reese <breese_at_[hidden]>
Date: Wed, 3 Sep 2025 01:02:28 +0200
On 9/2/25 23:59, Sebastian Wittmeier via Std-Proposals wrote:

> There is lots of complex code out there using those implicit conversions
> from bool to 0 and 1.
Which is particularly useful in generic branch-free programming that
works for both scalar and SIMD types. For example

   template <typename T>
   T sgn(T x) {
     return (x >= T(0) - (x <= T(0));
   }

   template <typename T>
   T max0(T x) {
      // max(0, x)
      return x * (x > T(0));
   }

While SIMD relational operations return a mask, it serves the same
purpose as a bool in the scalar case.

Received on 2025-09-02 23:02:36