I see 3.3K items in the ziglang issues and do not want to spam that. However sometimes I feel the urge to do a little proposal. Would this one be crazy?
Following the latest ArrayList - ArrayListUnmanaged changes, we see an empty constant defined inside the unmanaged versions:
Wouldnt it be nice the have sprinkled here and there an empty const defined in the std library where appropriate? For example the std.bit_set.IntegerBitSet.
const bits = std.bit_set.IntegerBitSet(64);
const x = bits.empty; // nicer.
const x = bits.initEmpty(); // less nice.
A related question (me bit twiddling in my program).
Are there convenient ways to test / set / clear bits? Builtins would be nice.
Or are there somehwere hidden in the std some functions?
Sometimes I used the std bitset but other times a need raw masks.
This is not a language proposal. It’s standard library proposal and they are much more welcome. If you make a PR implementing this changes it will probably be merged.
const Bits = std.bit_set.IntegerBitSet(64);
const x : Bits = .empty;
And I think it is better/nicer to read when you use decl-literals.
Having defined constants for .empty and .full would be nice.
I think the regular approach would be to add the new constants and document the old functions as deprecated, which then would be removed in the next release cycle after the new way was added.
You could make pos a usize or even a std.math.Log2Int(@TypeOf(mask)).
Also const bitcount = @typeInfo(@TypeOf(mask)).int.bits is probably safer than @bitSizeOf().
And you could do .{ .mask = @bitCast(mask) } to be agnostic towards signedness if that’s desired (e.g. if mask is a c_int).
You could assert std.meta.hasUniqueRepresentation(@TypeOf(mask)) and use @bitSizeOf(mask) that way the function could also be used with for example packed structs.
Yeah that is indeed a little akward, I suspect that it’s done like this to to keep the APIs of StaticBitSet and DynamicBitSet as similiar as possible.
If you’re using wrapper functions anyways it should always be safe to @truncate the returned usize to a Log2Int though.
I personally would really love to see plain 'ol slices get the same treatment, though I realize this would be beyond the scope of a standard library change.
It would be so much nicer and more expressive than the &.{} syntax, which I have never learned to like.
I never did that. Afraid to mess up
I’ll ask my intelligent daughter to help
Most important rule for creating a Github PR: after forking the upstream project, do your changes in its own uniquely named branch and create the PR from that branch, and don’t reuse branches for other PRs, instead delete the branch after the PR has been merged.
Makes both your life and the root project maintainer’s life easier
Yeah. I first have to go through learning how to use all that PR stuff!
This month I have an insane amount of database conversion stuff to do for my job. So if anyone feels the urge to put these zeroes and ones (yes better naming that is @mnemnion) in feel free to do that.
There goes my chance for immortality.