From c07c43bf911f62ad6363c024b3f81ceb4f95b16c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 2 Aug 2026 00:45:05 +0200 Subject: Report field access errors --- include/elna/boot/name_analysis.h | 6 ++---- include/elna/boot/result.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'include') 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 original; std::optional base; }; - using payload_type = std::variant; + using payload_type = std::variant; 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; + } }; /** -- cgit v1.2.3