zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 5c1428ea9db6c455fdd36b60fe6cd27b9e8eae4d (tree)
parent 3d23ba9c352b93a299d17e85d9a758cfac613d23
Author: Eric Eastwood <madlittlemods@gmail.com>
Date:   Mon, 11 Dec 2023 16:04:43 -0600

Add `getPtrConstAssertContains(...)` for compatibility with a `const` `std.EnumMap`

This way people can use `const` with a `std.EnumMap`
and be able to `getPtrAssertContains(...)` like the
would with a mutable `var` instance.

Aligns with the existing `getPtr(...)`/`getPtrConst(...)`
methods.
Diffstat:
Mlib/std/enums.zig | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib/std/enums.zig b/lib/std/enums.zig @@ -1086,6 +1086,14 @@ pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: ?fn (type) t return &self.values[index]; } + /// Gets the address of the const value associated with a key. + /// The key must be present in the map. + pub fn getPtrConstAssertContains(self: *const Self, key: Key) *const Value { + const index = Indexer.indexOf(key); + assert(self.bits.isSet(index)); + return &self.values[index]; + } + /// Adds the key to the map with the supplied value. /// If the key is already in the map, overwrites the value. pub fn put(self: *Self, key: Key, value: Value) void {