42 void PreludeTest::testInvokableWithConst ()
44 const auto lambda = [] (
const QString&) {};
49 QCOMPARE (
true,
true);
52 void PreludeTest::testInvokableWithNonConst ()
54 const auto lambda = [] (QString&) {};
59 QCOMPARE (
true,
true);
74 void PreludeTest::testMapList ()
77 const auto& otherList =
Map (list, [] (
int v) {
return QString::number (v); });
79 QCOMPARE (otherList, (QStringList {
"1",
"2",
"3" }));
82 void PreludeTest::testMapMap ()
84 const auto& map = GetSimpleMap ();
85 const auto& otherList =
Map (map, [] (
const QString& v) {
return v.size (); });
87 QCOMPARE (otherList, (
QList<int> { 3, 3, 3 }));
90 void PreludeTest::testMapMapMutatingVoid ()
92 auto map = GetSimpleMap ();
93 Map (map, [] (QString& v) { v += v [0]; });
95 QCOMPARE (map, (Util::MakeMap<int, QString> ({ { 0,
"aaaa" }, { 1,
"bbbb" }, { 2,
"cccc" }})));
102 constexpr
bool FailsImpl (
typename std::result_of<F (
void*)>::type*)
108 constexpr
bool FailsImpl (...)
114 constexpr
bool Fails ()
116 return FailsImpl<F> (0);
120 void PreludeTest::testMapMapMutatingVoidConst ()
124 auto lambda = [] (
const auto&)
126 const auto& map = GetSimpleMap ();
127 Map (map, [] (QString& v) { v +=
"a"; });
129 static_assert (Fails<decltype (lambda)> (),
130 "the code should fail");
132 QCOMPARE (
true,
true);
136 void PreludeTest::testMapMapNonMutatingVoid ()
138 auto map = GetSimpleMap ();
139 Map (map, [] (
const QString&) {});
141 QCOMPARE (map, GetSimpleMap ());
144 void PreludeTest::testMapMapNonMutatingVoidConst ()
146 const auto& map = GetSimpleMap ();
147 Map (map, [] (
const QString&) {});
149 QCOMPARE (map, GetSimpleMap ());
152 void PreludeTest::testMapStringList ()
154 const QStringList list {
"aaa",
"bbb",
"ccc" };
155 const auto& result =
Map (list, [] (
const QString& s) {
return s.size (); });
160 void PreludeTest::testMapMapStlized ()
162 const auto& map = GetSimpleMap ();
163 const auto& list =
Map (
Stlize (map), [] (
const std::pair<int, QString>& pair) {
return pair.second; });
165 QCOMPARE (list, QStringList { map.values () });
168 void PreludeTest::testMapMember ()
176 const QList<Test> tests { { 1, 2 }, { 2, 4 }, { 3, 6 } };
177 const auto& ints =
Map (tests, &Test::m_a);
182 void PreludeTest::testMapMemberFunction ()
195 const auto& ints =
Map (tests, &Test::GetA);
auto Stlize(Assoc &&assoc) -> detail::StlAssocRange< decltype(assoc.begin()), Assoc, PairType >
Converts an Qt's associative sequence assoc to an STL-like iteratable range.
auto Map(const Container< T > &c, F f) -> typename std::enable_if<!std::is_same< void, decltype(Invoke(f,*c.begin()))>::value, WrapType_t< Container< typename std::decay< decltype(Invoke(f,*c.begin()))>::type >>>::type
constexpr bool IsInvokableWithConst()