Hello Alejandro,

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).

Thanks for the suggestion but I believe this won't work for the use case where the bitset exceeds 64 bits right? >From C23 paper (emphasis mine)[1]:

Extended integer types, least-width integer types, and exact-width integer types, can all be used with the type-generic macros since the type-generic macros are required to work over all standard (unsigned) integer types and extended (unsigned) integer types, while excluding bool and bit-precise (_BitInt(N)) integer types that do not match pre-existing type widths.


References:

--
Sincerely,
Madhur Chauhan

“To live is the rarest thing in the world. Most people exist, that is all.”
- Oscar Wilde