mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
Bindings::get(): Add convenience method
This allows writing attribute lookups as
if (auto name = value.attrs->get(state.sName))
...
(cherry picked from commit f216c76c56
)
This commit is contained in:
parent
50d483a2c1
commit
0d118ef0c9
1 changed files with 9 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "symbol-table.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -63,6 +64,14 @@ public:
|
|||
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 end() { return &attrs[size_]; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue