From 54801ed6ad4e0ea8faa67b0b4ba10debeb824d3b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Jan 2017 16:06:50 +0100 Subject: Bindings: Add a method for iterating in lexicographically sorted order --- src/libexpr/attr-set.hh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/libexpr/attr-set.hh') diff --git a/src/libexpr/attr-set.hh b/src/libexpr/attr-set.hh index 7cf6a9c58086..e1fc2bf6d796 100644 --- a/src/libexpr/attr-set.hh +++ b/src/libexpr/attr-set.hh @@ -75,6 +75,19 @@ public: size_t capacity() { return capacity_; } + /* Returns the attributes in lexicographically sorted order. */ + std::vector lexicographicOrder() const + { + std::vector 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; }; -- cgit 1.4.1