Skip to content

Commit

Permalink
Merge pull request #12201 from daschuer/nonConstErase
Browse files Browse the repository at this point in the history
Introduce wrapper for non const iterators for erase and insert
  • Loading branch information
Swiftb0y authored Oct 22, 2023
2 parents 920fa8a + cb30cc9 commit c4204d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/preferences/dialog/dlgprefmixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ constexpr int kFrequencyLowerLimit = 16;
constexpr int kXfaderGridHLines = 3;
constexpr int kXfaderGridVLines = 5;

bool isMixingEQ(EffectManifest* pManifest) {
bool isMixingEQ(const EffectManifest* pManifest) {
return pManifest->isMixingEQ();
}

Expand Down Expand Up @@ -1175,11 +1175,11 @@ const QList<EffectManifestPointer> DlgPrefMixer::getDeckEqManifests() const {
allManifests.end(),
[](const auto& pManifest) { return isMixingEQ(pManifest.data()); });
if (m_eqEffectsOnly) {
constErase(&allManifests, nonEqsStartIt, allManifests.end());
erase(&allManifests, nonEqsStartIt, allManifests.end());
} else {
// Add a null item between EQs and non-EQs. The combobox fill function
// will use this to insert a separator.
constInsert(&allManifests, nonEqsStartIt, EffectManifestPointer());
insert(&allManifests, nonEqsStartIt, EffectManifestPointer());
}
return allManifests;
}
Expand Down
28 changes: 28 additions & 0 deletions src/util/make_const_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ typename C::const_iterator constErase(C* pContainer, I begin, I end) {
#endif
}

template<typename C, typename I>
typename C::iterator erase(C* pContainer, I begin, I end) {
#if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return pContainer->erase(make_const_iterator(*pContainer, begin),
make_const_iterator(*pContainer, end));
#else
return pContainer->erase(begin, end);
#endif
}

template<typename C, typename I>
typename C::const_iterator constErase(C* pContainer, I it) {
#if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Expand All @@ -43,6 +53,15 @@ typename C::const_iterator constErase(C* pContainer, I it) {
#endif
}

template<typename C, typename I>
typename C::iterator erase(C* pContainer, I it) {
#if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return pContainer->erase(make_const_iterator(*pContainer, it));
#else
return pContainer->erase(it);
#endif
}

template<typename C, typename I, class T>
typename C::const_iterator constInsert(C* pContainer, I before, T t) {
#if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Expand All @@ -52,3 +71,12 @@ typename C::const_iterator constInsert(C* pContainer, I before, T t) {
pContainer->insert(make_iterator(pContainer, before), t));
#endif
}

template<typename C, typename I, class T>
typename C::iterator insert(C* pContainer, I before, T t) {
#if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return pContainer->insert(make_const_iterator(*pContainer, before), std::move(t));
#else
return pContainer->insert(before, t);
#endif
}

0 comments on commit c4204d2

Please sign in to comment.