> For the complete documentation index, see [llms.txt](https://enma-1.gitbook.io/enma/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://enma-1.gitbook.io/enma/addons/maps.md).

# Maps

`std::map<K, V>` (sorted by key, `operator<`) and `std::unordered_map<K, V>` (hash, unspecified order) come from the `std` prelude — available in every script, no import.

```cpp
std::map<std::string, int64> m;
m["a"] = 1;                       // operator[]: inserts a default V on miss
m.insert("b", 2);                 // no-op if the key exists (C++ insert)
int64 v = m.at("a");              // throws on a missing key
if (m.contains("b")) { m.erase("b"); }
for (auto [k, v] : m) { ... }     // sorted iteration for std::map
```

## Shared surface

```cpp
map()                              // empty
map(const map<K, V>&)              // copy
map<K, V> m = {{k1, v1}, {k2, v2}};  // init-list (first key wins on dups)

m.size()      m.empty()
m[k]                               // V& — inserts default-constructed V on miss;
                                   //      assignment overwrites
m.at(k)                            // value on hit; THROWS on miss
m.insert(k, v)                     // first-wins: no-op if k exists
m.contains(k)
m.find(k)                          // iterator; == m.end() on miss
m.erase(k)                         // bool: removed?
m.clear()
m.begin()  m.end()
```

Values are stored by value: inserting copies, `at` returns a copy, `m[k] = v` assigns through the slot (memberwise `operator=`, no copy constructor — exactly C++).

## std::map only (ordered)

Keys sort ascending by the key type's `operator<` — a key type needs only `<`, nothing else.

```cpp
m.lower_bound(k)                   // iterator to first key >= k
m.upper_bound(k)                   // iterator to first key >  k
```

## std::unordered\_map only

Hash-based; iteration order is unspecified.

```cpp
m.reserve(n)
```

## Iteration

```cpp
for (auto [k, v] : m) { ... }          // structured binding per entry
for (auto it = m.begin(); !(it == m.end()); ++it) {
    auto [k, v] = *it;
}
std::next(it)   std::next(it, n)       // advance a copy
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://enma-1.gitbook.io/enma/addons/maps.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
