Skip to content

Adds generic typesafe simple ll #23590

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 5 commits into
base: master
Choose a base branch
from

Conversation

ityonemo
Copy link
Contributor

just something to consider. If it's not merged, I don't mind, but I think having a typesafe (simple) option will prevent people from footgunning themselves. Also could serve as a reference for someone who wants to build their own typesafe versions for more complex situations.

@matklad
Copy link
Contributor

matklad commented Apr 21, 2025

If we do this, then type-safe version should delegate to type-erased one, instead of being a reimplementation. See https://github.com/tigerbeetle/tigerbeetle/blob/main/src/stack.zig for an example.

No strong opinion on whether std should or should not include such a type-safe wrapper, but I'd personally lean towards no, in the interesting of simplicity.

@ityonemo
Copy link
Contributor Author

ityonemo commented Apr 29, 2025

I think if you read the commentary here: https://news.ycombinator.com/item?id=43679707 it's clear that @fieldParentPtr is sufficiently confusing and not being typesafe is also a magnet for (justifiable) criticism. A typesafe impl could serve to help "teach" readers of the code:

  • how to restore type safety from type erased systems
  • how to use/the meaning of @fieldParentPtr

An API that is "closer to what people expect from a linked list is good" but I agree that delegation would be better. I couldn't figure out how to square the circle on the first pass but I have some ideas and may take another swipe at it later today.

@ityonemo
Copy link
Contributor Author

thanks @matklad it was way easier than I thought, I don't know why I made things more complicated the first time around.

@ityonemo ityonemo force-pushed the adds-generic-typesafe-simple-LL branch from 38a9f6b to 79f7da3 Compare April 30, 2025 15:23
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.

2 participants