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

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

Ivorforce
Copy link
Member

@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 <iterator> must be added in two spots. This is unlikely to observably affect compile times.

@Ivorforce
Copy link
Member 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 :)

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me.

@Ivorforce Ivorforce force-pushed the std-size branch 2 times, most recently from 1dad219 to cf9d3a5 Compare February 6, 2025 16:02
…out the codebase.
@Repiteo Repiteo modified the milestones: 4.x, 4.5 Feb 14, 2025
@Repiteo Repiteo merged commit c937b6d into godotengine:master Mar 7, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Mar 7, 2025

Thanks!

@Ivorforce Ivorforce deleted the std-size branch March 7, 2025 22:54
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.

None yet

6 participants