#polymorphic procedure that works on things with a certain member
1 messages · Page 1 of 1 (latest)
Do you mean that you want it to not compile if a and b don't have foo fields?
I would generally suggest just having one specific type that you know about, instead of making it polymorphic.
yeah i do
the gimmick i'm going for is i have different types that can be constructed into linked lists and one set of helpers to do all of that
like my entities are like that but so are things in my ui tree
Not sure how much I recommend it, but you can do it with a where clause
how can I check the field?
is there a different approach you like?
You can do proc(a, b: $T) where intrinsics.type_has_field(T, "foo") {}, but I'm not sure where clauses give you good errors.
I would generally suggest that you make a proc for each type of thing
Perhaps a procgroup
ahh i see
That's what I do in my own project in the one place I do this
does where check at compile time?
Yes
kk
i'll see how well where works and do the proc group if it isn't working
thanks a ton!
The procgroup approach is probably better; trying to pretend to be Rust probably isn't gonna work out very well 🤣
i'm trying to pretend to be c
Trying to work out the exact incantation you need in order to actually get the correct where clause is more work than just writing out a proc for each one, morethanlike
If you've got literally 20 different structs all with different foo field types, then maybe - but in all seriousness, core:container/intrusive/list is a thing
it does look pretty tricky
never knew, thanks!