Bindings: Add convenience method for requiring an attribute

(cherry picked from commit fb692e5f7b)
This commit is contained in:
Eelco Dolstra 2019-05-31 23:44:42 +02:00
parent 0d118ef0c9
commit 79142cbbe1

View file

@ -72,6 +72,14 @@ public:
return {}; return {};
} }
Attr & need(const Symbol & name, const Pos & pos = noPos)
{
auto a = get(name);
if (!a)
throw Error("attribute '%s' missing, at %s", name, pos);
return **a;
}
iterator begin() { return &attrs[0]; } iterator begin() { return &attrs[0]; }
iterator end() { return &attrs[size_]; } iterator end() { return &attrs[size_]; }