commit c4dbfd5ae17ac7ca4dc267bf769134febe55e77e (tree)
parent ae69fb87eb76a9555f429c66ca695ce2b4015972
Author: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com>
Date: Mon, 24 Apr 2023 00:40:22 +0300
std.enums: make Ext parameter optional
According to #8169 optional generic functions work fine in comptime so it's possible
Diffstat:
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git 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;