From 1cf0fa06332712e41e132dd8fce1198c89351e6e Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 8 Mar 2024 09:51:40 +0100 Subject: add ExprAttrs::AttrDef::chooseByKind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit in place of inherited() — not quite useful yet since we don't distinguish plain and inheritFrom attr kinds so far. (cherry picked from commit 1f542adb3e18e7078e6a589182a53a47d971748a) Change-Id: If948c9d43e875de18f213a73a06a36f7c335b536 --- src/libexpr/nixexpr.hh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/libexpr/nixexpr.hh') diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index fe75592f0..246221c0f 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -172,6 +172,20 @@ struct ExprAttrs : Expr AttrDef() { }; bool inherited() const { return kind == Kind::Inherited; } + + template + const T & chooseByKind(const T & plain, const T & inherited, const T & inheritedFrom) const + { + switch (kind) { + case Kind::Plain: + return plain; + case Kind::Inherited: + return inherited; + default: + case Kind::InheritedFrom: + return inheritedFrom; + } + } }; typedef std::map AttrDefs; AttrDefs attrs; -- cgit v1.2.3