std.enums: make Ext parameter optional

According to #8169 optional generic functions work fine in comptime so it's possible
This commit is contained in:
Bogdan Romanyuk 2023-04-24 00:40:22 +03:00 committed by Veikka Tuominen
parent ae69fb87eb
commit c4dbfd5ae1

View File

@ -747,13 +747,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {
return IndexedArray(EnumIndexer(E), V, mixin.EnumArrayExt); return IndexedArray(EnumIndexer(E), V, mixin.EnumArrayExt);
} }
/// Pass this function as the Ext parameter to Indexed* if you fn NoExtension(comptime Self: type) type {
/// 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 {
_ = Self; _ = Self;
return NoExt; return NoExt;
} }
@ -762,12 +756,12 @@ const NoExt = struct {};
/// A set type with an Indexer mapping from keys to indices. /// A set type with an Indexer mapping from keys to indices.
/// Presence or absence is stored as a dense bitfield. This /// Presence or absence is stored as a dense bitfield. This
/// type does no allocation and can be copied by value. /// 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); comptime ensureIndexer(I);
return struct { return struct {
const Self = @This(); const Self = @This();
pub usingnamespace Ext(Self); pub usingnamespace (Ext orelse NoExtension)(Self);
/// The indexing rules for converting between keys and indices. /// The indexing rules for converting between keys and indices.
pub const Indexer = I; 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 /// 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.
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); comptime ensureIndexer(I);
return struct { return struct {
const Self = @This(); const Self = @This();
pub usingnamespace Ext(Self); pub usingnamespace (Ext orelse NoExtension)(Self);
/// The index mapping for this map /// The index mapping for this map
pub const Indexer = I; 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. /// A dense array of values, using an indexed lookup.
/// This type does no allocation and can be copied by value. /// 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); comptime ensureIndexer(I);
return struct { return struct {
const Self = @This(); const Self = @This();
pub usingnamespace Ext(Self); pub usingnamespace (Ext orelse NoExtension)(Self);
/// The index mapping for this map /// The index mapping for this map
pub const Indexer = I; pub const Indexer = I;