diff --git a/src/base/bittorrent/torrenthandleimpl.cpp b/src/base/bittorrent/torrenthandleimpl.cpp index 53f654d1d..431825a60 100644 --- a/src/base/bittorrent/torrenthandleimpl.cpp +++ b/src/base/bittorrent/torrenthandleimpl.cpp @@ -2133,9 +2133,9 @@ QVector TorrentHandleImpl::availableFileFractions() const const TorrentInfo::PieceRange filePieces = info.filePieces(i); int availablePieces = 0; - for (int piece = filePieces.first(); piece <= filePieces.last(); ++piece) { + for (const int piece : filePieces) availablePieces += (piecesAvailability[piece] > 0) ? 1 : 0; - } + res.push_back(static_cast(availablePieces) / filePieces.size()); } return res; diff --git a/src/base/http/httperror.h b/src/base/http/httperror.h index ab597ea64..853d6a7a9 100644 --- a/src/base/http/httperror.h +++ b/src/base/http/httperror.h @@ -39,8 +39,8 @@ public: QString statusText() const; private: - const int m_statusCode; - const QString m_statusText; + int m_statusCode; + QString m_statusText; }; class BadRequestHTTPError : public HTTPError diff --git a/src/base/indexrange.h b/src/base/indexrange.h index a297d76ed..88719e5a0 100644 --- a/src/base/indexrange.h +++ b/src/base/indexrange.h @@ -38,7 +38,8 @@ class IndexInterval public: using IndexType = Index; - IndexInterval(IndexType first, IndexType last) // add constexpr when using C++17 + // TODO: add constexpr when using C++17 + IndexInterval(const IndexType first, const IndexType last) : m_first {first} , m_last {last} { @@ -56,12 +57,12 @@ public: } private: - const IndexType m_first; - const IndexType m_last; + IndexType m_first; + IndexType m_last; }; template -constexpr IndexInterval makeInterval(T first, T last) +constexpr IndexInterval makeInterval(const T first, const T last) { return {first, last}; } @@ -74,13 +75,55 @@ public: using IndexType = Index; using IndexDiffType = IndexDiff; + class Iterator + { + public: + explicit constexpr Iterator(const IndexType index) + : m_index {index} + { + } + + constexpr Iterator(const Iterator &) = default; + + constexpr IndexType operator*() const + { + return m_index; + } + + constexpr Iterator &operator++() + { + ++m_index; + return *this; + } + + constexpr Iterator operator++(int) + { + const Iterator iter {*this}; + ++(*this); + return iter; + } + + constexpr bool operator==(const Iterator &other) const + { + return (*(*this) == *other); + } + + constexpr bool operator!=(const Iterator &other) const + { + return !(*this == other); + } + + private: + IndexType m_index; + }; + constexpr IndexRange() : m_first {0} , m_size {0} { } - constexpr IndexRange(IndexType first, IndexDiffType size) + constexpr IndexRange(const IndexType first, const IndexDiffType size) : m_first {first} , m_size {size} { @@ -92,14 +135,14 @@ public: { } - constexpr IndexType begin() const + constexpr Iterator begin() const { - return m_first; + return Iterator {m_first}; } - constexpr IndexType end() const + constexpr Iterator end() const { - return (m_first + m_size); + return Iterator {m_first + m_size}; } constexpr IndexDiffType size() const diff --git a/src/gui/previewselectdialog.h b/src/gui/previewselectdialog.h index 969a594e0..51d5a0213 100644 --- a/src/gui/previewselectdialog.h +++ b/src/gui/previewselectdialog.h @@ -48,6 +48,7 @@ class PreviewListDelegate; class PreviewSelectDialog final : public QDialog { Q_OBJECT + Q_DISABLE_COPY(PreviewSelectDialog) public: enum PreviewColumn diff --git a/src/gui/rss/automatedrssdownloader.h b/src/gui/rss/automatedrssdownloader.h index d158ecee2..0c2c3768a 100644 --- a/src/gui/rss/automatedrssdownloader.h +++ b/src/gui/rss/automatedrssdownloader.h @@ -53,6 +53,7 @@ namespace Ui class AutomatedRssDownloader : public QDialog { Q_OBJECT + Q_DISABLE_COPY(AutomatedRssDownloader) public: explicit AutomatedRssDownloader(QWidget *parent = nullptr); diff --git a/src/webui/api/apierror.h b/src/webui/api/apierror.h index e9181ca07..3879bd3af 100644 --- a/src/webui/api/apierror.h +++ b/src/webui/api/apierror.h @@ -47,5 +47,5 @@ public: APIErrorType type() const; private: - const APIErrorType m_type; + APIErrorType m_type; };