authorgravatar for madlittlemods@gmail.comEric Eastwood <madlittlemods@gmail.com> 2023-12-11 16:04:43-06:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-12-11 22:04:43+00:00
log5c1428ea9db6c455fdd36b60fe6cd27b9e8eae4d
treee5a15b3e227ceea85f04d53ff3c53b22327acf10
parent3d23ba9c352b93a299d17e85d9a758cfac613d23
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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.

1 files changed, 8 insertions(+), 0 deletions(-)

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