Skip to content
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

Improve const correctness #1446

Open
DanRStevens opened this issue Mar 12, 2024 · 0 comments
Open

Improve const correctness #1446

DanRStevens opened this issue Mar 12, 2024 · 0 comments

Comments

@DanRStevens
Copy link
Member

There are a number of places in the code that can and should be using const, but currently aren't. I thought I'd create an issue to track such updates in one place.

One notable example is the use of getStructures, and iterating over the corresponding Structure* elements.


Related to the above, it should be noted that when auto deduces a pointer type, applying const to it will apply to the pointer, not the underlying type. This is similar to type aliases with using and typedef. When a type alias refers to a pointer, applying const to the alias applies it to the pointer, not the underlying pointed to type.

Example of auto deducing Structure*:

    for (auto structure : storage)

Applying const to the above will deduce Structure* const, which may not be what was intended:

    for (const auto structure : storage)

Most likely the intended type is const Structure*, which can be deduced using auto* instead of auto.

Example with deduced type const Structure*:

    for (const auto* structure : storage)
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

No branches or pull requests

1 participant