Skip to content

Does std.BoundedArray really need constSlice? #24003

Closed as not planned
Closed as not planned
@ghost

Description

std.BoundedArray seems to be the only exception in the standard library that has an extra function constSlice() as an alternative to slice() to return a constant slice []const Type instead of []Type instead.

My proposal is to remove constSlice() and rename slice() to items() to be more similar to the other list types, such as the items field of std.ArrayList or the items() function of std.MultiArrayList. If std.BoundedArray has both of those why don't std.ArrayList and std.MultiArrayList etc. additionally have constItems or constSlice?

I suppose the pattern is that you're supposed to use constSlice wherever possible and slice only if needed to prevent accidental mutations. But I think the language already does enough here that this is not really needed? At least I've never been bitten with just using slice() everywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions