@@ -147,11 +147,10 @@ LockFile::LockFile(const fetchers::Settings & fetchSettings, std::string_view co
147147 if (version < 5 || version > 7 )
148148 throw Error (" lock file '%s' has unsupported version %d" , path, version);
149149
150- std::map<std::string, ref<Node>> nodeMap;
151-
152- std::function<void (Node & node, const nlohmann::json & jsonNode)> getInputs;
150+ std::string rootKey = json[" root" ];
151+ std::map<std::string, ref<Node>> nodeMap{{rootKey, root}};
153152
154- getInputs = [&](Node & node, const nlohmann::json & jsonNode) {
153+ [&](this const auto & getInputs, Node & node, const nlohmann::json & jsonNode) {
155154 if (jsonNode.find (" inputs" ) == jsonNode.end ())
156155 return ;
157156 for (auto & i : jsonNode[" inputs" ].items ()) {
@@ -179,11 +178,7 @@ LockFile::LockFile(const fetchers::Settings & fetchSettings, std::string_view co
179178 throw Error (" lock file contains cycle to root node" );
180179 }
181180 }
182- };
183-
184- std::string rootKey = json[" root" ];
185- nodeMap.insert_or_assign (rootKey, root);
186- getInputs (*root, json[" nodes" ][rootKey]);
181+ }(*root, json[" nodes" ][rootKey]);
187182
188183 // FIXME: check that there are no cycles in version >= 7. Cycles
189184 // between inputs are only possible using 'follows' indirections.
@@ -197,9 +192,7 @@ std::pair<nlohmann::json, LockFile::KeyMap> LockFile::toJSON() const
197192 KeyMap nodeKeys;
198193 boost::unordered_flat_set<std::string> keys;
199194
200- std::function<std::string (const std::string & key, ref<const Node> node)> dumpNode;
201-
202- dumpNode = [&](std::string key, ref<const Node> node) -> std::string {
195+ auto dumpNode = [&](this auto & dumpNode, std::string key, ref<const Node> node) -> std::string {
203196 auto k = nodeKeys.find (node);
204197 if (k != nodeKeys.end ())
205198 return k->second ;
@@ -276,17 +269,13 @@ std::optional<FlakeRef> LockFile::isUnlocked(const fetchers::Settings & fetchSet
276269{
277270 std::set<ref<const Node>> nodes;
278271
279- std::function<void (ref<const Node> node)> visit;
280-
281- visit = [&](ref<const Node> node) {
272+ [&](this const auto & visit, ref<const Node> node) {
282273 if (!nodes.insert (node).second )
283274 return ;
284275 for (auto & i : node->inputs )
285276 if (auto child = std::get_if<0 >(&i.second ))
286277 visit (*child);
287- };
288-
289- visit (root);
278+ }(root);
290279
291280 /* Return whether the input is either locked, or, if
292281 `allow-dirty-locks` is enabled, it has a NAR hash. In the
@@ -332,9 +321,7 @@ std::map<InputAttrPath, Node::Edge> LockFile::getAllInputs() const
332321 std::set<ref<Node>> done;
333322 std::map<InputAttrPath, Node::Edge> res;
334323
335- std::function<void (const InputAttrPath & prefix, ref<Node> node)> recurse;
336-
337- recurse = [&](const InputAttrPath & prefix, ref<Node> node) {
324+ [&](this const auto & recurse, const InputAttrPath & prefix, ref<Node> node) {
338325 if (!done.insert (node).second )
339326 return ;
340327
@@ -345,9 +332,7 @@ std::map<InputAttrPath, Node::Edge> LockFile::getAllInputs() const
345332 if (auto child = std::get_if<0 >(&input))
346333 recurse (inputAttrPath, *child);
347334 }
348- };
349-
350- recurse ({}, root);
335+ }({}, root);
351336
352337 return res;
353338}
0 commit comments