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

Use std::size instead of sizeof(a) / sizeof(a[0]) pattern throughout the codebase. #102419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ivorforce
Copy link
Contributor

@Ivorforce Ivorforce commented Feb 4, 2025

Identified this in a discussion.

In short, std::size is the canonical way to determine the number of elements in a C-style array starting from C++17. Using it looks slightly cleaner than the sizeof(a) / sizeof(a[0]) pattern, and is less error prone to regressions.
I took the opportunity to add constexpr to a few of the affected variables (where possible).

The change does have one downside, which is that #include <array> must be added in two spots. This is unlikely to observably affect compile times.

@Ivorforce
Copy link
Contributor Author

Ivorforce commented Feb 4, 2025

FYI I got the compiler error fixed, but I'm waiting to rebase on top of #102396 when it's merged, to modify the sizeof it's adding :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants