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<FieldName> 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 <edward.welbourne@qt.io>
This commit is contained in:
Marc Mutz 2022-07-18 11:20:56 +02:00
parent 3174f44579
commit 25de37381d

View File

@ -12,6 +12,8 @@
#include "QtCore/private/qgregoriancalendar_p.h" // for yearSharingWeekDays()
#include <q20algorithm.h>
#ifdef Q_OS_WIN
# include <qt_windows.h>
# include <time.h>
@ -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;