Let it be a template with requirement of such behavior:
template<typename MyActionLambda>
void enumerateChildrenByTag(QDomNodeList& list, const QString& tag, MyActionLambda action )
{
for(int i = 0; i < list.size(); i++) {
QDomElement el = list.item(i).firstChildElement(tag);
while(!el.isNull())
{
if( typeid(decltype(action(el))) == typeid(SomeType) )
{
auto res = action(el)
// do something with res
}
else
// do something with action(el)
el = el.nextSiblingElement(tag);
}
}
}
this obviously would be impossible in way it is written for lambda to have void return type, because both branches of if() should be legal. Is there a simpler way to resolve this except making declspec as a default value of template parameter and specialize two templates?
Aucun commentaire:
Enregistrer un commentaire