mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std.IndexedSet.iterator: allow iteration on const EnumSet
This commit is contained in:
parent
270b6c4c2f
commit
90477e5c10
@ -878,7 +878,7 @@ pub fn IndexedSet(comptime I: type, comptime Ext: fn (type) type) type {
|
|||||||
/// index order. Modifications to the set during iteration
|
/// index order. Modifications to the set during iteration
|
||||||
/// may or may not be observed by the iterator, but will
|
/// may or may not be observed by the iterator, but will
|
||||||
/// not invalidate it.
|
/// not invalidate it.
|
||||||
pub fn iterator(self: *Self) Iterator {
|
pub fn iterator(self: *const Self) Iterator {
|
||||||
return .{ .inner = self.bits.iterator(.{}) };
|
return .{ .inner = self.bits.iterator(.{}) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -970,6 +970,24 @@ test "pure EnumSet fns" {
|
|||||||
try testing.expect(full.differenceWith(black).eql(red));
|
try testing.expect(full.differenceWith(black).eql(red));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "std.enums.EnumSet const iterator" {
|
||||||
|
const Direction = enum { up, down, left, right };
|
||||||
|
const diag_move = init: {
|
||||||
|
var move = EnumSet(Direction).initEmpty();
|
||||||
|
move.insert(.right);
|
||||||
|
move.insert(.up);
|
||||||
|
break :init move;
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = EnumSet(Direction).initEmpty();
|
||||||
|
var it = diag_move.iterator();
|
||||||
|
while (it.next()) |dir| {
|
||||||
|
result.insert(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
try testing.expect(result.eql(diag_move));
|
||||||
|
}
|
||||||
|
|
||||||
/// A map from keys to values, using an index lookup. Uses a
|
/// A map from keys to values, using an index lookup. Uses a
|
||||||
/// bitfield to track presence and a dense array of values.
|
/// bitfield to track presence and a dense array of values.
|
||||||
/// This type does no allocation and can be copied by value.
|
/// This type does no allocation and can be copied by value.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user