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 {
747747 return IndexedArray(EnumIndexer(E), V, mixin.EnumArrayExt);
748748}
749749
750/// Pass this function as the Ext parameter to Indexed* if you
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 {
750fn NoExtension(comptime Self: type) type {
757751 _ = Self;
758752 return NoExt;
759753}
......@@ -762,12 +756,12 @@ const NoExt = struct {};
762756/// A set type with an Indexer mapping from keys to indices.
763757/// Presence or absence is stored as a dense bitfield. This
764758/// 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 {
766760 comptime ensureIndexer(I);
767761 return struct {
768762 const Self = @This();
769763
770 pub usingnamespace Ext(Self);
764 pub usingnamespace (Ext orelse NoExtension)(Self);
771765
772766 /// The indexing rules for converting between keys and indices.
773767 pub const Indexer = I;
......@@ -1007,12 +1001,12 @@ test "std.enums.EnumSet const iterator" {
10071001/// A map from keys to values, using an index lookup. Uses a
10081002/// bitfield to track presence and a dense array of values.
10091003/// 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 {
10111005 comptime ensureIndexer(I);
10121006 return struct {
10131007 const Self = @This();
10141008
1015 pub usingnamespace Ext(Self);
1009 pub usingnamespace (Ext orelse NoExtension)(Self);
10161010
10171011 /// The index mapping for this map
10181012 pub const Indexer = I;
......@@ -1167,12 +1161,12 @@ pub fn IndexedMap(comptime I: type, comptime V: type, comptime Ext: fn (type) ty
11671161
11681162/// A dense array of values, using an indexed lookup.
11691163/// 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 {
11711165 comptime ensureIndexer(I);
11721166 return struct {
11731167 const Self = @This();
11741168
1175 pub usingnamespace Ext(Self);
1169 pub usingnamespace (Ext orelse NoExtension)(Self);
11761170
11771171 /// The index mapping for this map
11781172 pub const Indexer = I;