From 809567230905b912f0e163a66a911dbfe847ea4d Mon Sep 17 00:00:00 2001 From: Artur Wieczorek <7330332+a-wi@users.noreply.github.com> Date: Sat, 6 Jan 2024 18:19:59 +0100 Subject: [PATCH] Use std::array instead of raw array in wxSystemColourProperty --- src/propgrid/advprops.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index 31708e6cd0..e23c7ce60c 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -766,7 +766,8 @@ void wxFontProperty::OnCustomPaint(wxDC& dc, #include "wx/colordlg.h" -static const char* const gs_cp_es_syscolour_labels[] = { +static constexpr std::array gs_cp_es_syscolour_labels +{ /* TRANSLATORS: Keyword of system colour */ wxTRANSLATE("AppWorkspace"), /* TRANSLATORS: Keyword of system colour */ wxTRANSLATE("ActiveBorder"), /* TRANSLATORS: Keyword of system colour */ wxTRANSLATE("ActiveCaption"), @@ -795,7 +796,13 @@ static const char* const gs_cp_es_syscolour_labels[] = { nullptr }; -static const long gs_cp_es_syscolour_values[] = { +#if wxCHECK_CXX_STD(201402L) // [] is constexpr since C++14 +static_assert(gs_cp_es_syscolour_labels[gs_cp_es_syscolour_labels.size() - 1] == nullptr, + "nullptr has to mark the end of table"); +#endif // >= C++ 14 + +static constexpr std::array gs_cp_es_syscolour_values +{ wxSYS_COLOUR_APPWORKSPACE, wxSYS_COLOUR_ACTIVEBORDER, wxSYS_COLOUR_ACTIVECAPTION, @@ -823,6 +830,8 @@ static const long gs_cp_es_syscolour_values[] = { wxPG_COLOUR_CUSTOM }; +static_assert(gs_cp_es_syscolour_values.size() == gs_cp_es_syscolour_labels.size() - 1, + "Colour values table has to have one item less than colour labels table"); IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID) @@ -859,8 +868,8 @@ wxSystemColourProperty::wxSystemColourProperty( const wxString& label, const wxS const wxColourPropertyValue& value ) : wxEnumProperty( label, name, - gs_cp_es_syscolour_labels, - gs_cp_es_syscolour_values, + gs_cp_es_syscolour_labels.data(), + gs_cp_es_syscolour_values.data(), &gs_wxSystemColourProperty_choicesCache ) { Init( value.m_type, value.m_colour );