mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 23:12:44 +01:00
Bindings::get(): Add convenience method
This allows writing attribute lookups as
if (auto name = value.attrs->get(state.sName))
...
This commit is contained in:
parent
6d118419f2
commit
c3b55a96a7
1 changed files with 9 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
#include "gc.hh"
|
#include "gc.hh"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
@ -68,6 +69,14 @@ public:
|
||||||
return end();
|
return end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<Attr *> get(const Symbol & name)
|
||||||
|
{
|
||||||
|
Attr key(name, 0);
|
||||||
|
iterator i = std::lower_bound(begin(), end(), key);
|
||||||
|
if (i != end() && i->name == name) return &*i;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
iterator begin() { return &attrs[0]; }
|
iterator begin() { return &attrs[0]; }
|
||||||
iterator end() { return &attrs[size_]; }
|
iterator end() { return &attrs[size_]; }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue