Skip to content

Codechange: replace auto_array with std::vector#63

Merged
PeterN merged 1 commit intoOpenTTD:masterfrom
PeterN:replace-auto-array
Mar 10, 2026
Merged

Codechange: replace auto_array with std::vector#63
PeterN merged 1 commit intoOpenTTD:masterfrom
PeterN:replace-auto-array

Conversation

@PeterN
Copy link
Member

@PeterN PeterN commented Mar 10, 2026

auto_array is a strange contraption to handle dynamically-sized arrays.

  • It does not allocate the array itself, that's manually created with new[] externally, and then passed in via an implicit constructor.
  • It does deallocate the array with delete[] in its destructor.
  • Sometimes it's inherited, sometimes it's a member variable.

Replace all uses with std::vector instead.

The code using this looks pretty fragile, so access to the vector elements is via the at() method, instead of array indexer.

Touched code has been auto-formatted for readibility...

@PeterN PeterN force-pushed the replace-auto-array branch from 7bfff26 to c6cffdb Compare March 10, 2026 19:55
@rubidium42
Copy link
Contributor

Have you noticed that MSVC is complaining quite a bit about size_t vs uint?

@PeterN PeterN force-pushed the replace-auto-array branch from c6cffdb to 3ca0d8a Compare March 10, 2026 20:46
@PeterN
Copy link
Member Author

PeterN commented Mar 10, 2026

Have you noticed that MSVC is complaining quite a bit about size_t vs uint?

Not any more.

@PeterN PeterN merged commit c47695b into OpenTTD:master Mar 10, 2026
6 checks passed
@PeterN PeterN deleted the replace-auto-array branch March 10, 2026 21:16
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

Successfully merging this pull request may close these issues.

2 participants