| ... | ... | @@ -452,7 +452,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type { |
| 452 | 452 | values: [Indexer.count]Value = undefined, |
| 453 | 453 | |
| 454 | 454 | /// Initializes the map using a sparse struct of optionals |
| 455 | | pub fn init(init_values: EnumFieldStruct(E, ?Value, null)) Self { |
| 455 | pub fn init(init_values: EnumFieldStruct(E, ?Value, @as(?Value, null))) Self { |
| 456 | 456 | @setEvalBranchQuota(2 * @typeInfo(E).Enum.fields.len); |
| 457 | 457 | var result: Self = .{}; |
| 458 | 458 | if (@typeInfo(E).Enum.is_exhaustive) { |
| ... | ... | @@ -652,6 +652,19 @@ pub fn EnumMap(comptime E: type, comptime V: type) type { |
| 652 | 652 | }; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | test EnumMap { |
| 656 | const Ball = enum { red, green, blue }; |
| 657 | |
| 658 | const some = EnumMap(Ball, u8).init(.{ |
| 659 | .green = 0xff, |
| 660 | .blue = 0x80, |
| 661 | }); |
| 662 | try testing.expectEqual(2, some.count()); |
| 663 | try testing.expectEqual(null, some.get(.red)); |
| 664 | try testing.expectEqual(0xff, some.get(.green)); |
| 665 | try testing.expectEqual(0x80, some.get(.blue)); |
| 666 | } |
| 667 | |
| 655 | 668 | /// A multiset of enum elements up to a count of usize. Backed |
| 656 | 669 | /// by an EnumArray. This type does no dynamic allocation and can |
| 657 | 670 | /// be copied by value. |