Algorithm: Add a member variant for transform

Change-Id: I329ee764cc13dd8b794c6769a2baf2f41d6a9983
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Orgad Shaneh
2017-03-09 22:11:11 +02:00
committed by Orgad Shaneh
parent bc562bbea9
commit 4136e36c6f
2 changed files with 24 additions and 10 deletions

View File

@@ -42,6 +42,16 @@ int stringToInt(const QString &s)
return s.toInt();
}
namespace {
struct Struct
{
Struct(int m) : member(m) {}
bool operator==(const Struct &other) const { return member == other.member; }
int member;
};
}
void tst_Algorithm::transform()
{
// same container type
@@ -110,16 +120,11 @@ void tst_Algorithm::transform()
Utils::sort(i3);
QCOMPARE(i3, QList<int>({1, 1, 3}));
}
}
namespace {
struct Struct
{
Struct(int m) : member(m) {}
bool operator==(const Struct &other) const { return member == other.member; }
int member;
};
{
const QList<Struct> list({4, 3, 2, 1, 2});
const QList<int> trans = Utils::transform(list, &Struct::member);
QCOMPARE(trans, QList<int>({4, 3, 2, 1, 2}));
}
}
void tst_Algorithm::sort()