Skip to content

remove .slice() and .constSlice() from std.BoundedArray in lieu of .items() #24007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

VisenDev
Copy link

closes #24003

@wooster0
Copy link
Contributor

I wouldn’t mark this as closing the issue because it doesn’t rename slice() to items() as proposed.

@VisenDev
Copy link
Author

I wouldn’t mark this as closing the issue because it doesn’t rename slice() to items() as proposed.

Oh I missed that, I'll make that change

@VisenDev VisenDev changed the title remove std.BoundedArray.constSlice() remove .slice() and .constSlice() from std.BoundedArray in lieu of .items() May 29, 2025
@Fri3dNstuff
Copy link
Contributor

This PR might be a good time to change the way .items() calculates its return type - the current way:

switch (@TypeOf(&self.buffer)) {
    *align(alignment.toByteUnits()) [buffer_capacity]T => []align(alignment.toByteUnits()) T,
    *align(alignment.toByteUnits()) const [buffer_capacity]T => []align(alignment.toByteUnits()) const T,
    else => unreachable,
}

is needlessly long, and quite hard to understand at first glance (especially if you don't know that receiver arguments in an anytype are by-reference) - I suggest it be changed to:

switch (@TypeOf(self)) {
    *Self => []align(alignment.toByteUnits()) T,
    *const Self => []align(alignment.toByteUnits()) const T,
    else => @compileError("Bad type"),
}

It does mean that the method will no longer cope with over-aligned arguments, but I don't think it's ever something that'll be encountered in practice...

@VisenDev
Copy link
Author

switch (@TypeOf(self)) {
    *Self => []align(alignment.toByteUnits()) T,
    *const Self => []align(alignment.toByteUnits()) const T,
    else => @compileError("Bad type"),
}

Sure I can make that change. I'll update that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does std.BoundedArray really need constSlice?
3 participants