Date: Wed, 21 May 2025 11:59:15 -0400
On Wed, May 21, 2025 at 11:34 AM Teodoro Freund via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> [...]
> I hope to start a conversation, and maybe draft up a paper, on adding
> more powerful accesor methods for `std::bitset`.
>
Relevant:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0161r0.pdf
Also relevant:
https://quuxplusone.github.io/blog/2022/11/05/bit-vectors/
And see the vast amount of work Peng Liu has been doing in libc++ on
speeding up bit-by-bit iterator algorithms. (E.g.:
https://github.com/llvm/llvm-project/issues/133111 )
These improvements are useful today only for vector<bool>. (An example,
which seems actually very much worse than I would expect, given all the
hoops libc++ jumps through to try to make this codegen good instead of bad:
https://godbolt.org/z/EPaEEW34v Seems like std::copy isn't getting inlined
when it should, and also isn't falling back to memcpy when it should.)
Anyway, the way I'd like to be able to transfer bits from a std::bitset
into an array of longs would be:—
#include <bit> // for std::endian
#include <bitset>
#include <algorithm>
unsigned char a[100];
std::bitset<800> bs = { true, false, false, false, true, false, false,
true, ~~~~ };
auto bits = *std::views::bits*(a, std::endian::big);
// fantasy: creates a std::ranges::bits_view<~~~> referring to `a`
std::copy(*bs.begin(), bs.end()*, bits.begin());
// fantasy: std::bitset should expose bit-iterators, somehow
(although see why it doesn't
<https://quuxplusone.github.io/blog/2022/11/05/bit-vectors/#std-bitset-is-one-of-those-not-q>)
— perhaps this could be std::ranges::copy(*bs.bits()*, bits.begin())
instead?
// QoI fantasy: std::copy should have an optimized implementation
when both sides are bit-iterators
assert(a[0] == 0x89);
assert(a[1] == ~~~~); // etc etc
HTH,
Arthur
std-proposals_at_[hidden]> wrote:
> [...]
> I hope to start a conversation, and maybe draft up a paper, on adding
> more powerful accesor methods for `std::bitset`.
>
Relevant:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0161r0.pdf
Also relevant:
https://quuxplusone.github.io/blog/2022/11/05/bit-vectors/
And see the vast amount of work Peng Liu has been doing in libc++ on
speeding up bit-by-bit iterator algorithms. (E.g.:
https://github.com/llvm/llvm-project/issues/133111 )
These improvements are useful today only for vector<bool>. (An example,
which seems actually very much worse than I would expect, given all the
hoops libc++ jumps through to try to make this codegen good instead of bad:
https://godbolt.org/z/EPaEEW34v Seems like std::copy isn't getting inlined
when it should, and also isn't falling back to memcpy when it should.)
Anyway, the way I'd like to be able to transfer bits from a std::bitset
into an array of longs would be:—
#include <bit> // for std::endian
#include <bitset>
#include <algorithm>
unsigned char a[100];
std::bitset<800> bs = { true, false, false, false, true, false, false,
true, ~~~~ };
auto bits = *std::views::bits*(a, std::endian::big);
// fantasy: creates a std::ranges::bits_view<~~~> referring to `a`
std::copy(*bs.begin(), bs.end()*, bits.begin());
// fantasy: std::bitset should expose bit-iterators, somehow
(although see why it doesn't
<https://quuxplusone.github.io/blog/2022/11/05/bit-vectors/#std-bitset-is-one-of-those-not-q>)
— perhaps this could be std::ranges::copy(*bs.bits()*, bits.begin())
instead?
// QoI fantasy: std::copy should have an optimized implementation
when both sides are bit-iterators
assert(a[0] == 0x89);
assert(a[1] == ~~~~); // etc etc
HTH,
Arthur
Received on 2025-05-21 15:59:28