#Is there a way to create a function that takes an array/slice which only has comptime known len?

1 messages · Page 1 of 1 (latest)

hoary gull
#
    pub fn view(self: *World, comptime Components: anytype, tags: []Entity) EcsError!View(Components, tags.len) {
        assert(@typeInfo(@TypeOf(Components)) == .Struct);
        assert(Components.len > 0 and Components.len <= std.math.maxInt(ComponentIx));

        var components: [Components.len + tags.len]Entity = undefined;
        inline for (Components, 0..) |T, ix| {
            components[ix] = try self.componentFromType(T);
        }

        for (tags, Components.len..) |tag, ix| {
            components[ix] = tag;
        }

        return .{
            .world = self,
            .components = components,
        };
    }

I will know the length of tags a comptime, but not the values

#

I guess I could make the tags anytype and verify it's an array

#

ok, doing that works, it would be cool if I could have just the length be comptime known though

zinc glade