Created
June 22, 2025 03:55
-
-
Save mitchcurtis/d84294c89839befdb96d2956e045e456 to your computer and use it in GitHub Desktop.
Getting additions and removals from two lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QDebug> | |
void printChanges(QList<QString> existingList, QList<QString> newList) | |
{ | |
std::sort(existingList.begin(), existingList.end()); | |
std::sort(newList.begin(), newList.end()); | |
QList<QString> added; | |
std::set_difference(newList.constBegin(), newList.constEnd(), | |
existingList.constBegin(), existingList.constEnd(), std::back_inserter(added)); | |
qDebug() << "added" << added; | |
QList<QString> removed; | |
std::set_difference(existingList.constBegin(), existingList.constEnd(), | |
newList.constBegin(), newList.constEnd(), std::back_inserter(removed)); | |
qDebug() << "removed" << removed << "\n"; | |
} | |
int main( | |
int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
// Expected output: | |
// added QList() | |
// removed QList() | |
printChanges({ "a", "b" }, { "a", "b" }); | |
// Expected output: | |
// added QList("c") | |
// removed QList() | |
printChanges({ "a", "b" }, { "a", "b", "c" }); | |
// Expected output: | |
// added QList() | |
// removed QList("b") | |
printChanges({ "a", "b" }, { "a" }); | |
// Expected output: | |
// added QList() | |
// removed QList() | |
printChanges({ "a", "b" }, { "b", "a" }); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment