Cleanup: Ghost: use function instead of macro for ARRAY_SIZE

This implementation matches `ARRAY_SIZE` in `BLI_utildefines.hh`.

Pull Request: https://projects.blender.org/blender/blender/pulls/162715
This commit is contained in:
Jacques Lucke 2026-08-18 15:20:05 +02:00
parent 8014ae0e02
commit fa8f54fd0f
2 changed files with 9 additions and 9 deletions

View file

@ -3607,9 +3607,9 @@ static void gwl_window_csd_active_elem_button(GWL_Seat *seat,
GHOST_TCSD_Type press_type = GHOST_kCSDTypeBody;
bool is_double_click = false;
if (ebutton < ARRAY_SIZE(GHOST_CSD_EventState::buttons)) {
GHOST_CSD_EventState &event_state = win->csd_eventstate_get();
if (ebutton < ARRAY_SIZE(event_state.buttons)) {
const GHOST_CSD_Params &params = seat->system->getWindowCSD();
GHOST_CSD_EventState &event_state = win->csd_eventstate_get();
GHOST_CSD_EventState_Button &event_button = event_state.buttons[ebutton];
if (event_button.action_history_num >= 1) {

View file

@ -10,6 +10,8 @@
#pragma once
#include <cstddef>
#include "GHOST_utildefines_variadic.hh"
/* -------------------------------------------------------------------- */
@ -32,13 +34,11 @@
* \{ */
/* Assuming a static array. */
#if defined(__GNUC__) && !defined(__cplusplus) && !defined(__clang__) && !defined(__INTEL_COMPILER)
# define ARRAY_SIZE(arr) \
((sizeof(struct { int isnt_array : ((const void *)&(arr) == &(arr)[0]); }) * 0) + \
(sizeof(arr) / sizeof(*(arr))))
#else
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
#endif
template<class T, size_t N> constexpr size_t ARRAY_SIZE(const T (&arg)[N]) noexcept
{
(void)arg;
return N;
}
/** \} */