From a2845ece82c7a1ace40402218151ecde823a1def Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 12 Nov 2022 11:12:39 +0100 Subject: [PATCH] cleanup: use range based for in download code This removes a constant describing the length of the array. The enumerated_range code had to be adapted, because the interaction of C-type arrays with the C++ typesystem is mad. With C-type arrays, one has to pass a reference to std::declval. Signed-off-by: Berthold Stoeger --- core/downloadfromdcthread.cpp | 10 +++++----- core/range.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index 6c38812c9..c52d0062b 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -1,6 +1,7 @@ #include "downloadfromdcthread.h" #include "core/libdivecomputer.h" #include "core/qthelper.h" +#include "core/range.h" #include "core/settings/qPrefDiveComputer.h" #include "core/divelist.h" #include @@ -58,23 +59,22 @@ static void updateRememberedDCs() qPrefDiveComputer::set_device1(qPrefDiveComputer::device()); } -#define NUMTRANSPORTS 7 -static QString transportStringTable[NUMTRANSPORTS] = { +static QString transportStringTable[] = { QStringLiteral("SERIAL"), QStringLiteral("USB"), QStringLiteral("USBHID"), QStringLiteral("IRDA"), QStringLiteral("BT"), QStringLiteral("BLE"), - QStringLiteral("USBSTORAGE"), + QStringLiteral("USBSTORAGE") }; static QString getTransportString(unsigned int transport) { QString ts; - for (int i = 0; i < NUMTRANSPORTS; i++) { + for (auto [i, s]: enumerated_range(transportStringTable)) { if (transport & 1 << i) - ts += transportStringTable[i] + ", "; + ts += s + ", "; } ts.chop(2); return ts; diff --git a/core/range.h b/core/range.h index 561424079..ad38b9dc2 100644 --- a/core/range.h +++ b/core/range.h @@ -40,7 +40,7 @@ class enumerated_range { Range &base; public: - using base_iterator = decltype(std::begin(std::declval())); + using base_iterator = decltype(std::begin(std::declval())); class iterator { int idx; base_iterator it;