Answer the question
In order to leave comments, you need to log in
C++ lambdas: how to make a function that takes a lambda expression?
I'm working with QAbstractItemModel and I have to do something like this.
• Test 1 failed → return QVariant().
• Test 2 failed → return QVariant().
All checks passed - we display some information.
Decided to rewrite this business on lambdas.
Let's simplify the task.
struct Entry {
float lo, hi;
};
class GetData {
public:
virtual QVariant get(const Entry& en) const = 0;
};
QVariant GetLo : public GetData {
public:
QVariant get(const Entry& en) const override { return en.lo; }
static const GetLo INSTANCE;
}
QVariant entryToVar(const Entry* en, const GetData& getData) {
if (en == nullptr) return QVariant();
return getData.get(*en);
}
…
QVariant vLo = entryToVar(pEntry, GetLo::INSTANCE);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question