OutpostUniverse / OPHD

OutpostHD - Open source remake of Sierra On-Line's Outpost
BSD 3-Clause "New" or "Revised" License
109 stars 20 forks source link

Improve `const` correctness #1446

Open DanRStevens opened 8 months ago

DanRStevens commented 8 months ago

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)