diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-08-02 00:45:05 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-08-02 00:45:05 +0200 |
| commit | c07c43bf911f62ad6363c024b3f81ceb4f95b16c (patch) | |
| tree | d536b942ecede49741c090e61337947a26fbe030 /include | |
| parent | e9cd3e5d0157f145dc0c3fea59f434fdd5ae55c6 (diff) | |
| download | elna-c07c43bf911f62ad6363c024b3f81ceb4f95b16c.tar.gz | |
Report field access errors
Diffstat (limited to 'include')
| -rw-r--r-- | include/elna/boot/name_analysis.h | 6 | ||||
| -rw-r--r-- | include/elna/boot/result.h | 22 |
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; + } }; /** |
