-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Rationale behind int and not std::size_t #3351
Comments
Speaking about point indices, I assume that Speaking of container size, could you post a link to some examples of what you mean? |
I'm really convinced it is/was just a byproduct of code review absence. |
Take |
Ah, OK. Yes, I fully agree with Sergio's opinion. |
I remember if not careful using Also if you read the google coding style here
|
Good point. I think this issue comes while looping forwards too (while using unsigned for eg.). If we agree on converting
Sadly, I hit the limit of It's a bit hard to argue what can be "too big" and maybe we could limit use of |
Just chiming in with the CppCoreGuidelines link as to the reasons why a signed index should be preferred in normal use cases. It requires having |
@aPonza Yes. That's the big issue. Signed size everywhere would make so much more sense. As for negative indices not used anywhere, it turns out, PCL uses one special value as marker, ie: -1 when item is not found else correct positive index. A redesign by using I've been trying to remove use of indices as much as possible and use range for loops or algorithms instead. One thing that's controversial is that I'm converting all internal index counters to I'm hoping that by the time we finish converting loops to range-for + algorithms, the remainder will be taken care of by using range-adapters among other solutions. There are only a few places where the index is required and ranges allow using adapters or rewriting the code to eliminate a lot of them |
Hi, I made this commit where I replaced I am for the introduction of a Regarding the actual type of indices, I would argue for an unsigned type (e.g.
|
Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs. |
|
Is there a reason for using
int
and notstd::size_t
everywhere to represent size, including size of stdlib containers?EDIT:
I've noticed an inconsistency. Several places use
std::size_t
, others do not.Expected Behavior
Current Behavior
Possible Solution
Use
std::size_t
instead ofint
for indicesstd::size_t
is recommended for portabilityThe text was updated successfully, but these errors were encountered: