about summary refs log tree commit diff
path: root/src/libexpr/attr-set.hh
diff options
context:
space:
mode:
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 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<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;
 };