Bindings: Add a method for iterating in lexicographically sorted order

This commit is contained in:
Eelco Dolstra
2017-01-26 20:40:33 +01:00
parent b1f001538e
commit 54801ed6ad
4 changed files with 28 additions and 28 deletions
+13
View File
@@ -75,6 +75,19 @@ public:
size_t capacity() { return capacity_; }
/* Returns the attributes in lexicographically sorted order. */
std::vector<const Attr *> lexicographicOrder() const
{
std::vector<const Attr *> res;
res.reserve(size_);
for (size_t n = 0; n < size_; n++)
res.emplace_back(&attrs[n]);
std::sort(res.begin(), res.end(), [](const Attr * a, const Attr * b) {
return (string) a->name < (string) b->name;
});
return res;
}
friend class EvalState;
};