C++ Logo

std-proposals

Advanced search

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

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Wed, 21 May 2025 21:37:26 +0200
śr., 21 maj 2025 o 20:57 Jonathan Wakely via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
> 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.

`std::bitset` is slow depending on use, if the number of bits is not
multiples of 64
then many of the operations have overhead (to remove tail bits of
storage that do not fit size).
In some cases `std::bitset_atleast` would improve some uses cases
where tails bits are ignorable.

> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-05-21 19:37:44