C++ Logo


Advanced search

Re: [std-proposals] [bitset] find first set bit after a position pos

From: Alejandro Colomar <alx.manpages_at_[hidden]>
Date: Tue, 25 Oct 2022 00:45:28 +0200
[resend; mailing list issues]

Hello Madhur,

On 10/24/22 17:19, Madhur Chauhan via Std-Proposals wrote:
> Hello everybody,
> *Problem*: Find the first set bit in a bitset with index >= a givenpos
> *Current Solution*: Run a simple loop over bits.
> *Preferred solution*: Run a loop *over words *instead of bits. libstdc++
> implements this extension as _Find_next()[1].
> /Preferred solution/ is 90x faster [2] than its counterpart. Due of lack of
> standard functionality users have to either use pick a horribly slow solution or
> hope for vendor's extension.

Or, you can consider using ISO C (C23), which should be "usable" within C++.

There's <stdbit.h> and the stdc_leading_zeros{c,s,i,l,ll}(3) family of
functions, and the stdc_leading_zeros(3) type-generic function (which might be
unavailable in C++, or maybe they implement it as an overloaded function, or
maybe an 'auto' macro; we'll see).

It's not yet available, but should be in a few months or a year. If you care
about performance, that's probably as fast as it gets.




Received on 2022-10-24 22:45:31