-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
JointIndex should not be iterable #21866
Comments
cc @agarwal-abhinav who unearthed the bug in #21860 which was introduced in #21308 |
We would need a new type for indices that are not iterable. I've been using the term "ordinal" for consecutive, iterable indices (there is a type JointOrdinal in use by the topology code). Many of the existing index types are currently intended to be iterable but as we make more elements removable that will likely change. Maybe we should rename TypeSafeIndex to TypeSafeOrdinal, and invent a new, non-iterable class for anything that shouldn't be iterated. |
To me, the problem stems beyond whether this particular
The problem of "stale" indices still remains one way or another. We thought about this quite a bit in #21397 and #20711 and decided the simplest thing was to strongly encourage the use of It could be nice to expose the "ordinal" idea that we use internally. Maybe even disallow the use of APIs that expect |
I think that at a minimum we should document in I agree that not being able to write such loops would be best, but that'll rqeuire a larger effort. |
What happened?
It should not be possible to write the loop
as MultibodyPlant's joint indexes need not be contiguous (e.g. after calling
RemoveJoint
on the plant pre-finalize)I think one way to prevent this footgun would be to remove the increment/decrement methods from
JointIndex
. If this is an acceptable change, should this be done for all typesafe indices? (I haven't thought about this)The problem of course is that one could write:
Another possible solution would be to make multibody plant a friend of
JointIndex
and make theJointIndex
constructor protected.Version
No response
What operating system are you using?
No response
What installation option are you using?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: