forked from qt-creator/qt-creator
Simplify transform and add support for more input container types
Change-Id: Ib75cfcc7741be686c0117fbb27df869e14db4f69 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <array>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <valarray>
|
||||
|
||||
// must get included after the containers above or gcc4.9 will have a problem using
|
||||
@@ -235,6 +236,18 @@ void tst_Algorithm::transform()
|
||||
const std::vector<int> trans = Utils::transform(v, &Struct::member);
|
||||
QCOMPARE(trans, std::vector<int>({1, 2, 3, 4}));
|
||||
}
|
||||
{
|
||||
// std::unordered_map -> QList
|
||||
std::unordered_map<int, double> m;
|
||||
m.emplace(1, 1.5);
|
||||
m.emplace(3, 2.5);
|
||||
m.emplace(5, 3.5);
|
||||
QList<double> trans = Utils::transform<QList>(m, [](const std::pair<int, double> &in) {
|
||||
return in.first * in.second;
|
||||
});
|
||||
Utils::sort(trans);
|
||||
QCOMPARE(trans, QList<double>({1.5, 7.5, 17.5}));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Algorithm::sort()
|
||||
|
Reference in New Issue
Block a user