aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/elna/boot/name_analysis.h6
-rw-r--r--include/elna/boot/result.h22
2 files changed, 24 insertions, 4 deletions
diff --git a/include/elna/boot/name_analysis.h b/include/elna/boot/name_analysis.h
index ab86a44..996c357 100644
--- a/include/elna/boot/name_analysis.h
+++ b/include/elna/boot/name_analysis.h
@@ -75,14 +75,12 @@ namespace elna::boot
class member_error : public error
{
public:
- struct not_found
- {
- };
+ enum class kind { not_found, field_on_type };
struct duplicate {
std::optional<source_position> original;
std::optional<std::string> base;
};
- using payload_type = std::variant<not_found, duplicate>;
+ using payload_type = std::variant<duplicate, kind>;
member_error(const source_position position, const std::string& name,
const type& composite, payload_type payload);
diff --git a/include/elna/boot/result.h b/include/elna/boot/result.h
index 1455371..c73799d 100644
--- a/include/elna/boot/result.h
+++ b/include/elna/boot/result.h
@@ -473,6 +473,28 @@ namespace elna::boot
{
return this->payload.size();
}
+
+ /**
+ * Accesses an element by key.
+ *
+ * The key must exist — behaviour is undefined otherwise.
+ * Use \c find() for fallible lookup.
+ *
+ * \param key Key value of the element to look up.
+ * \return Reference to the mapped value.
+ */
+ mapped_type& operator[](const key_type& key)
+ {
+ return this->payload[this->index_map.find(key)->second].second;
+ }
+
+ /**
+ * \overload
+ */
+ const mapped_type& operator[](const key_type& key) const
+ {
+ return this->payload[this->index_map.find(key)->second].second;
+ }
};
/**