authorgravatar for wrongnull@gmail.comBogdan Romanyuk <wrongnull@gmail.com> 2023-04-24 00:40:22+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-05-10 16:15:41+03:00
logc4dbfd5ae17ac7ca4dc267bf769134febe55e77e
treea6c698407670a8964e0829882b5d250618ae0bad
parentae69fb87eb76a9555f429c66ca695ce2b4015972

std.enums: make Ext parameter optional

According to #8169 optional generic functions work fine in comptime so it's possible

1 files changed, 7 insertions(+), 13 deletions(-)

lib/std/enums.zig+7-13
...@@ -747,13 +747,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {...@@ -747,13 +747,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {
747 return IndexedArray(EnumIndexer(E), V, mixin.EnumArrayExt);747 return IndexedArray(EnumIndexer(E), V, mixin.EnumArrayExt);
748}748}
749749
750/// Pass this function as the Ext parameter to Indexed* if you750fn NoExtension(comptime Self: type) type {
751/// do not want to attach any extensions. This parameter was
752/// originally an optional, but optional generic functions
753/// seem to be broken at the moment.
754/// TODO: Once #8169 is fixed, consider switching this param
755/// back to an optional.
756pub fn NoExtension(comptime Self: type) type {
757 _ = Self;751 _ = Self;
758 return NoExt;752 return NoExt;
759}753}
...@@ -762,12 +756,12 @@ const NoExt = struct {};...@@ -762,12 +756,12 @@ const NoExt = struct {};
762/// A set type with an Indexer mapping from keys to indices.756/// A set type with an Indexer mapping from keys to indices.
763/// Presence or absence is stored as a dense bitfield. This757/// Presence or absence is stored as a dense bitfield. This
764/// type does no allocation and can be copied by value.758/// type does no allocation and can be copied by value.
765pub fn IndexedSet(comptime I: type, comptime Ext: fn (type) type) type {759pub fn IndexedSet(comptime I: type, comptime Ext: ?fn (type) type) type {
766 comptime ensureIndexer(I);760 comptime ensureIndexer(I);
767 return struct {761 return struct {
768 const Self = @This();762 const Self = @This();
769763
770 pub usingnamespace Ext(Self);764 pub usingnamespace (Ext orelse NoExtension)(Self);
771765
772 /// The indexing rules for converting between keys and indices.766 /// The indexing rules for converting between keys and indices.
773 pub const Indexer = I;767 pub const Indexer = I;
...@@ -1007,12 +1001,12 @@ test "std.enums.EnumSet const iterator" {...@@ -1007,12 +1001,12 @@ test "std.enums.EnumSet const iterator" {
1007/// A map from keys to values, using an index lookup. Uses a1001/// A map from keys to values, using an index lookup. Uses a
1008/// bitfield to track presence and a dense array of values.1002/// bitfield to track presence and a dense array of values.
1009/// This type does no allocation and can be copied by value.1003/// This type does no allocation and can be copied by value.
1010pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: fn (type) type) type {1004pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: ?fn (type) type) type {
1011 comptime ensureIndexer(I);1005 comptime ensureIndexer(I);
1012 return struct {1006 return struct {
1013 const Self = @This();1007 const Self = @This();
10141008
1015 pub usingnamespace Ext(Self);1009 pub usingnamespace (Ext orelse NoExtension)(Self);
10161010
1017 /// The index mapping for this map1011 /// The index mapping for this map
1018 pub const Indexer = I;1012 pub const Indexer = I;
...@@ -1167,12 +1161,12 @@ pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: fn (type) ty...@@ -1167,12 +1161,12 @@ pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: fn (type) ty
11671161
1168/// A dense array of values, using an indexed lookup.1162/// A dense array of values, using an indexed lookup.
1169/// This type does no allocation and can be copied by value.1163/// This type does no allocation and can be copied by value.
1170pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type) type) type {1164pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: ?fn (type) type) type {
1171 comptime ensureIndexer(I);1165 comptime ensureIndexer(I);
1172 return struct {1166 return struct {
1173 const Self = @This();1167 const Self = @This();
11741168
1175 pub usingnamespace Ext(Self);1169 pub usingnamespace (Ext orelse NoExtension)(Self);
11761170
1177 /// The index mapping for this map1171 /// The index mapping for this map
1178 pub const Indexer = I;1172 pub const Indexer = I;