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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-11-12 11:12:39 +01:00 committed by bstoeger
parent b61732da42
commit a2845ece82
2 changed files with 6 additions and 6 deletions

View file

@ -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 <QDebug>
@ -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;

View file

@ -40,7 +40,7 @@ class enumerated_range
{
Range &base;
public:
using base_iterator = decltype(std::begin(std::declval<Range>()));
using base_iterator = decltype(std::begin(std::declval<Range &>()));
class iterator {
int idx;
base_iterator it;