C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Faster access to std::bitset

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Wed, 21 May 2025 19:56:41 +0100
On Wed, 21 May 2025 at 16:34, Teodoro Freund via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> # Faster access to std::bitset
>
> Hello everyone, I want to open up discussion on some improvements
> I believe the committee should consider for the `std::bitset`
> structure, in particular related to how the underlaying data
> is accessed.
>
> `std::bitset` is a strange collection present on the standard,
> it's intended to abstract "a sequence consisting of a fixed
> number of bits", and it does that by allowing accessor methods
> to individual bits (`operator[]`) while at the same time allowing
> fast construction (destruction) from (to) *short* sequences of
> bits, `unsigned long` and `unsigned long long`.
>
> However, this access to the underlying properties of this structure
> break quite early on, since as soon as we want our `bitset` to keep
> more than 64 bits (in most platforms) we can't construct it from
> such a contiguous array of elements, nor can we extract the contiguous
> elements.
>
> I hope to start a conversation, and maybe draft up a paper, on adding
> more powerful accesor methods for `std::bitset`.
>
> ## `std::bitset` is a very slow sequence
>
> The main reason behind this proposal is that accessing the sequence
> of bits in the current implementation of `std::bitset` is slow, very slow.

What do you mean by "the current implementation of std::bitset"? There
are at least three widely used implementations, and nothing in the
standard says they have to be slow.

Received on 2025-05-21 18:56:58