41 void PreludeTest::testInvokableWithConst ()
43 const auto lambda = [] (
const QString&) {};
48 QCOMPARE (
true,
true);
51 void PreludeTest::testInvokableWithNonConst ()
53 const auto lambda = [] (QString&) {};
58 QCOMPARE (
true,
true);
73 void PreludeTest::testMapList ()
76 const auto& otherList =
Map (list, [] (
int v) {
return QString::number (v); });
78 QCOMPARE (otherList, (QStringList {
"1",
"2",
"3" }));
81 void PreludeTest::testMapMap ()
83 const auto& map = GetSimpleMap ();
84 const auto& otherList =
Map (map, [] (
const QString& v) {
return v.size (); });
86 QCOMPARE (otherList, (
QList<int> { 3, 3, 3 }));
89 void PreludeTest::testMapMapMutatingVoid ()
91 auto map = GetSimpleMap ();
92 Map (map, [] (QString& v) { v += v [0]; });
94 QCOMPARE (map, (Util::MakeMap<int, QString> ({ { 0,
"aaaa" }, { 1,
"bbbb" }, { 2,
"cccc" }})));
101 constexpr
bool FailsImpl (
typename std::result_of<F (
void*)>::type*)
107 constexpr
bool FailsImpl (...)
113 constexpr
bool Fails ()
115 return FailsImpl<F> (0);
119 void PreludeTest::testMapMapMutatingVoidConst ()
123 auto lambda = [] (
const auto&)
125 const auto& map = GetSimpleMap ();
126 Map (map, [] (QString& v) { v +=
"a"; });
128 static_assert (Fails<decltype (lambda)> (),
129 "the code should fail");
131 QCOMPARE (
true,
true);
135 void PreludeTest::testMapMapNonMutatingVoid ()
137 auto map = GetSimpleMap ();
138 Map (map, [] (
const QString&) {});
140 QCOMPARE (map, GetSimpleMap ());
143 void PreludeTest::testMapMapNonMutatingVoidConst ()
145 const auto& map = GetSimpleMap ();
146 Map (map, [] (
const QString&) {});
148 QCOMPARE (map, GetSimpleMap ());
151 void PreludeTest::testMapMember ()
159 const QList<Test> tests { { 1, 2 }, { 2, 4 }, { 3, 6 } };
160 const auto& ints =
Map (tests, &Test::m_a);
165 void PreludeTest::testMapMemberFunction ()
178 const auto& ints =
Map (tests, &Test::GetA);
auto Map(const Container< T > &c, F f) -> typename std::enable_if<!std::is_same< void, decltype(Invoke(f, std::declval< T >()))>::value, WrapType_t< Container< typename std::decay< decltype(Invoke(f, std::declval< T >()))>::type >>>::type
constexpr bool IsInvokableWithConst()