1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Bindings: Add a method for iterating in lexicographically sorted order

This commit is contained in:
Eelco Dolstra 2017-01-25 16:06:50 +01:00
parent b1f001538e
commit 54801ed6ad
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
4 changed files with 28 additions and 28 deletions

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;
};