From e29a1ccf0af2e2890ec7b7fde82f0e53a1d0aad9 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Tue, 12 Aug 2025 14:54:53 +0300 Subject: [PATCH] libexpr: Use recursive lambda instead of std::function There's no reason to use a std::function for recursive lambdas since there are polymorphic lambdas. (cherry picked from commit a80a5c4dba0d944fab8f5ed57a343869ae96bf16) Upstream-PR: https://github.com/NixOS/nix/pull/13741 Change-Id: I593bd04597e2ae000374ca1eca4d8928e986c0b5 (cherry picked from commit 5badc1bc8a8ff3155b656276fee6e18f6e088533) --- lix/libexpr/primops/fromTOML.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lix/libexpr/primops/fromTOML.cc b/lix/libexpr/primops/fromTOML.cc index 191b4580c..a27604271 100644 --- a/lix/libexpr/primops/fromTOML.cc +++ b/lix/libexpr/primops/fromTOML.cc @@ -14,9 +14,7 @@ void prim_fromTOML(EvalState & state, Value ** args, Value & val) std::istringstream tomlStream(std::string{toml}); - std::function visit; - - visit = [&](Value & v, toml::value t) { + auto visit = [&](this const auto & self, Value & v, toml::value t) -> void { switch (t.type()) { case toml::value_t::table: { auto table = toml::get(t); @@ -30,7 +28,7 @@ void prim_fromTOML(EvalState & state, Value ** args, Value & val) auto attrs = state.ctx.buildBindings(size); for (auto & elem : table) { - visit(attrs.alloc(elem.first), elem.second); + self(attrs.alloc(elem.first), elem.second); } v.mkAttrs(attrs); @@ -41,7 +39,7 @@ void prim_fromTOML(EvalState & state, Value ** args, Value & val) size_t size = array.size(); v = state.ctx.mem.newList(size); for (size_t i = 0; i < size; ++i) { - visit(*(v.listElems()[i] = state.ctx.mem.allocValue()), array[i]); + self(*(v.listElems()[i] = state.ctx.mem.allocValue()), array[i]); } } break; case toml::value_t::boolean: