aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-10-14 12:31:21 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-10-14 12:34:32 +0200
commiteab934cb2a23595a7ac7c8a72373cd8096b606a9 (patch)
tree07498bd4a54627b6e822c5e2ba4839159392bd59 /src/libutil/util.hh
parent09b14ea97a7883114baa5878da163d9e403396d6 (diff)
Make the canReachRoots() traversal non-recursive
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r--src/libutil/util.hh11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 76f80f7a4..485ff4153 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -523,6 +523,17 @@ std::optional<typename T::value_type> remove_begin(T & c)
}
+/* Remove and return the first item from a container. */
+template <class T>
+std::optional<typename T::value_type> pop(T & c)
+{
+ if (c.empty()) return {};
+ auto v = std::move(c.front());
+ c.pop();
+ return v;
+}
+
+
template<typename T>
class Callback;