about summary refs log tree commit diff
path: root/src/libexpr/attr-set.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-01-25T15·06+0100
committerEelco Dolstra <edolstra@gmail.com>2017-01-26T19·40+0100
commit54801ed6ad4e0ea8faa67b0b4ba10debeb824d3b (patch)
tree3e8f94aad34c4b1011cf77b1f6527d3f09f2c502 /src/libexpr/attr-set.hh
parentb1f001538e41a4f28e315baeede93a8fe70d6d62 (diff)
Bindings: Add a method for iterating in lexicographically sorted order
Diffstat (limited to 'src/libexpr/attr-set.hh')
-rw-r--r--src/libexpr/attr-set.hh13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libexpr/attr-set.hh b/src/libexpr/attr-set.hh
index 7cf6a9c580..e1fc2bf6d7 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<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;
 };