Skip to content

Commit 5badc1b

Browse files
xokdviumemilazy
authored andcommitted
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: NixOS/nix#13741 Change-Id: I593bd04597e2ae000374ca1eca4d8928e986c0b5
1 parent 2ca5670 commit 5badc1b

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

lix/libexpr/primops/fromTOML.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ void prim_fromTOML(EvalState & state, Value ** args, Value & val)
1414

1515
std::istringstream tomlStream(std::string{toml});
1616

17-
std::function<void(Value &, toml::value)> visit;
18-
19-
visit = [&](Value & v, toml::value t) {
17+
auto visit = [&](this const auto & self, Value & v, toml::value t) -> void {
2018
switch (t.type()) {
2119
case toml::value_t::table: {
2220
auto table = toml::get<toml::table>(t);
@@ -30,7 +28,7 @@ void prim_fromTOML(EvalState & state, Value ** args, Value & val)
3028
auto attrs = state.ctx.buildBindings(size);
3129

3230
for (auto & elem : table) {
33-
visit(attrs.alloc(elem.first), elem.second);
31+
self(attrs.alloc(elem.first), elem.second);
3432
}
3533

3634
v.mkAttrs(attrs);
@@ -41,7 +39,7 @@ void prim_fromTOML(EvalState & state, Value ** args, Value & val)
4139
size_t size = array.size();
4240
v = state.ctx.mem.newList(size);
4341
for (size_t i = 0; i < size; ++i) {
44-
visit(*(v.listElems()[i] = state.ctx.mem.allocValue()), array[i]);
42+
self(*(v.listElems()[i] = state.ctx.mem.allocValue()), array[i]);
4543
}
4644
} break;
4745
case toml::value_t::boolean:

0 commit comments

Comments
 (0)