From 25de37381de37dab191bda85e6f1c2d172e6092e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 18 Jul 2022 11:20:56 +0200 Subject: QLocale/Win: statically assert that is_sorted(windows_to_iso_list) Consequently, remove the corresponding comment. Need to mark the array as constexpr in order to run q20::is_sorted on it. Instead of overloading op< (which would be wrong, because there's no one natural ordering of these entries), write the idiomatic manual mixed-mode comparator By and use that. A follow-up commit will use the same function object to replace the hand-written binary search with a call to lower_bound(). Task-number: QTBUG-103721 Change-Id: I47743b5620dc3cece73b2e5bae658d5a636554dd Reviewed-by: Edward Welbourne --- src/corelib/text/qlocale_win.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/corelib/text/qlocale_win.cpp') diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp index f67965539b..97ef7a3970 100644 --- a/src/corelib/text/qlocale_win.cpp +++ b/src/corelib/text/qlocale_win.cpp @@ -12,6 +12,8 @@ #include "QtCore/private/qgregoriancalendar_p.h" // for yearSharingWeekDays() +#include + #ifdef Q_OS_WIN # include # include @@ -888,8 +890,14 @@ struct WindowsToISOListElt { char iso_name[6]; }; -/* NOTE: This array should be sorted by the first column! */ -static const WindowsToISOListElt windows_to_iso_list[] = { +namespace { +struct ByWindowsCode { + constexpr bool operator()(WindowsToISOListElt lhs, WindowsToISOListElt rhs) const noexcept + { return lhs.windows_code < rhs.windows_code; } +}; +} // unnamed namespace + +static constexpr WindowsToISOListElt windows_to_iso_list[] = { { 0x0401, "ar_SA" }, { 0x0402, "bg\0 " }, { 0x0403, "ca\0 " }, @@ -1003,6 +1011,9 @@ static const WindowsToISOListElt windows_to_iso_list[] = { static const int windows_to_iso_count = sizeof(windows_to_iso_list)/sizeof(WindowsToISOListElt); +static_assert(q20::is_sorted(std::begin(windows_to_iso_list), std::end(windows_to_iso_list), + ByWindowsCode{})); + static const char *winLangCodeToIsoName(int code) { int cmp = code - windows_to_iso_list[0].windows_code; -- cgit v1.2.3