improve count variables

This commit is contained in:
pantor
2020-06-27 17:21:45 +02:00
parent bc020a5ee0
commit 390db9f2b7
2 changed files with 6 additions and 14 deletions

View File

@@ -20,13 +20,9 @@ struct Template {
/// Return number of variables (total number, not distinct ones) in the template
int count_variables() {
int result {0};
for (auto& n : nodes) {
if (n.flags == Node::Flag::ValueLookupDot || n.flags == Node::Flag::ValueLookupPointer) {
result += 1;
}
}
return result;
return std::count_if(nodes.cbegin(), nodes.cend(), [](const inja::Node &node) {
return (node.flags == Node::Flag::ValueLookupDot || node.flags == Node::Flag::ValueLookupPointer);
});
}
};

View File

@@ -2283,13 +2283,9 @@ struct Template {
/// Return number of variables (total number, not distinct ones) in the template
int count_variables() {
int result {0};
for (auto& n : nodes) {
if (n.flags == Node::Flag::ValueLookupDot || n.flags == Node::Flag::ValueLookupPointer) {
result += 1;
}
}
return result;
return std::count_if(nodes.cbegin(), nodes.cend(), [](const inja::Node &node) {
return (node.flags == Node::Flag::ValueLookupDot || node.flags == Node::Flag::ValueLookupPointer);
});
}
};