From c3073f43180871b483771ba9439feaa861cc862a Mon Sep 17 00:00:00 2001 From: Rangi Date: Tue, 21 Jul 2026 14:07:45 -0400 Subject: [PATCH] Assume that `InsertionOrderedMap` never `add`s duplicate keys --- include/itertools.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/itertools.hpp b/include/itertools.hpp index 0c7986a4..c61d0f87 100644 --- a/include/itertools.hpp +++ b/include/itertools.hpp @@ -12,7 +12,7 @@ #include #include -#include "helpers.hpp" // Enum +#include "helpers.hpp" // Enum, assume // A wrapper around iterables to reverse their iteration order; used in `for`-each loops. template @@ -55,12 +55,18 @@ public: typename decltype(list)::const_iterator begin() const { return list.begin(); } typename decltype(list)::const_iterator end() const { return list.end(); } + // Adding a key that already exists would make the previous value unreachable. + // `InsertionOrderedMap`s are only used for charmaps and sections, which each + // avoid `add`ing if already present, so we can `assume` this is not a concern. + ItemT &add(KeyT const &key) { + assume(!contains(key)); map[key] = list.size(); return list.emplace_back(); } ItemT &add(KeyT const &key, ItemT &&value) { + assume(!contains(key)); map[key] = list.size(); list.emplace_back(std::move(value)); return list.back();