diff --git a/lib/std/enums.zig b/lib/std/enums.zig index f44f8fd89d..aa6edd60b1 100644 --- a/lib/std/enums.zig +++ b/lib/std/enums.zig @@ -747,13 +747,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type { return IndexedArray(EnumIndexer(E), V, mixin.EnumArrayExt); } -/// Pass this function as the Ext parameter to Indexed* if you -/// do not want to attach any extensions. This parameter was -/// originally an optional, but optional generic functions -/// seem to be broken at the moment. -/// TODO: Once #8169 is fixed, consider switching this param -/// back to an optional. -pub fn NoExtension(comptime Self: type) type { +fn NoExtension(comptime Self: type) type { _ = Self; return NoExt; } @@ -762,12 +756,12 @@ const NoExt = struct {}; /// A set type with an Indexer mapping from keys to indices. /// Presence or absence is stored as a dense bitfield. This /// type does no allocation and can be copied by value. -pub fn IndexedSet(comptime I: type, comptime Ext: fn (type) type) type { +pub fn IndexedSet(comptime I: type, comptime Ext: ?fn (type) type) type { comptime ensureIndexer(I); return struct { const Self = @This(); - pub usingnamespace Ext(Self); + pub usingnamespace (Ext orelse NoExtension)(Self); /// The indexing rules for converting between keys and indices. pub const Indexer = I; @@ -1007,12 +1001,12 @@ test "std.enums.EnumSet const iterator" { /// A map from keys to values, using an index lookup. Uses a /// bitfield to track presence and a dense array of values. /// This type does no allocation and can be copied by value. -pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: fn (type) type) type { +pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: ?fn (type) type) type { comptime ensureIndexer(I); return struct { const Self = @This(); - pub usingnamespace Ext(Self); + pub usingnamespace (Ext orelse NoExtension)(Self); /// The index mapping for this map pub const Indexer = I; @@ -1167,12 +1161,12 @@ pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: fn (type) ty /// A dense array of values, using an indexed lookup. /// This type does no allocation and can be copied by value. -pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type) type) type { +pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: ?fn (type) type) type { comptime ensureIndexer(I); return struct { const Self = @This(); - pub usingnamespace Ext(Self); + pub usingnamespace (Ext orelse NoExtension)(Self); /// The index mapping for this map pub const Indexer = I;