1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-15 15:02:42 +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:
Eelco Dolstra 2018-11-26 19:57:20 +01:00
parent 6d118419f2
commit c3b55a96a7

View file

@ -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_]; }