docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영. - Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들 (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거. - Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/ Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/ Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이 존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존). - Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/ JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동. - 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리. - Topic_Programming 최종 문서 수: 2784 → 3985.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
---
|
||||
id: cpp-maps
|
||||
title: "C++ Maps"
|
||||
category: "Programming_Language"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["std::map", "key-value pairs C++", "C++ 맵"]
|
||||
duplicate_of: ""
|
||||
source_trust_level: "B"
|
||||
confidence_score: 0.86
|
||||
created_at: 2026-07-04
|
||||
updated_at: 2026-07-04
|
||||
review_reason: ""
|
||||
merge_history: []
|
||||
tags: ["cpp", "programming-language", "w3schools", "stl", "map"]
|
||||
raw_sources: ["https://www.w3schools.com/cpp/cpp_maps.asp"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[CPP Maps]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
`map` reuses set's "auto-sort + unique" behavior but shifts what must be unique from the ELEMENT itself to just the KEY, letting VALUES repeat freely — and it overloads `[]` with a dual meaning no other container has: `people["Jenny"] = 22;` on a key that doesn't exist SILENTLY CREATES it (unlike vector's `[]`, which never grows the container), meaning map's `[]` is simultaneously a read, a write, AND an insert operator depending on context, a three-way overload that requires `.at()` or `.count()` when you need to tell those cases apart. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **`map<keytype, valuetype> name`** — two type parameters instead of one, e.g. `map<string, int> people;`; requires `<map>`. [S1]
|
||||
- **Unique keys, non-unique values** — like set's uniqueness rule but applied only to the key half of each pair; values can repeat freely. [S1]
|
||||
- **Auto-sorted by key** — same ascending-order-by-default behavior as set, reversible with `greater<type>` as the third template parameter. [S1]
|
||||
- **`[]` as read/write/insert** — `people["John"]` reads the value for an existing key, `people["John"] = 50;` overwrites it, and `people["Jenny"] = 22;` on a NEW key silently inserts it — three distinct behaviors under one syntax. [S1]
|
||||
- **`.at()`** — safer read/write alternative that throws if the key doesn't exist, unlike `[]` which would silently create a new entry instead of erroring. [S1]
|
||||
- **`.insert({key, value})`** — explicit alternative to `[]` for adding; if the key already exists, the insert is silently ignored (first value wins, matching set's duplicate-drop behavior). [S1]
|
||||
- **`.count(key)`** — returns 1/0 to check key existence without risking an accidental insert. [S1]
|
||||
- **Looping requires `auto` + `.first`/`.second`** — `for (auto person : people) { cout << person.first << person.second; }`, since each element is a key-value pair, not a single value. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
- Declaration: `map<string, int> people = { {"John", 32}, {"Adele", 45}, {"Bo", 29} };`. [S1]
|
||||
- Access: `people["John"]`, `people.at("Adele")`; `.at()` throws for a missing key (`people.at("Jenny")` errors), while `people["Jenny"]` would just create it. [S1]
|
||||
- Duplicate-key insert is ignored: `people.insert({"Jenny", 22}); people.insert({"Jenny", 30});` keeps only 22. [S1]
|
||||
- Existence check without mutation: `people.count("John")` returns 1. [S1]
|
||||
- Loop pattern: `for (auto person : people) { cout << person.first << " is: " << person.second << "\n"; }` — output is sorted by key (Adele, Bo, John), not insertion order. [S1]
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
||||
- **[] 연산자가 vector와 다르게 동작함**: vector의 []는 존재하는 인덱스만 읽고 범위를 벗어나면 정의되지 않은 동작이었지만, map의 []는 존재하지 않는 키에 값을 대입하면 조용히 새 요소를 생성한다는 점이 vector와의 핵심 차이로 확인됨. [S1]
|
||||
- **set의 고유성 규칙이 키에만 적용되도록 완화됨**: set은 요소 전체가 고유해야 했지만, map은 키만 고유하면 되고 값은 자유롭게 중복될 수 있다는 점이 set 규칙의 부분적 완화로 확인됨. [S1]
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
사람 이름과 나이를 저장하는 map에서 값을 읽고, 수정하고, .count()로 존재 여부를 확인하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Map's `[]` reads, writes, AND silently inserts depending on context (C++):
|
||||
```cpp
|
||||
#include <map>
|
||||
map<string, int> people = { {"John", 32}, {"Adele", 45}, {"Bo", 29} };
|
||||
|
||||
people["Jenny"] = 22; // key doesn't exist -> silently inserted
|
||||
cout << people.at("Adele"); // safe read, throws if missing
|
||||
cout << people.count("John"); // 1 if exists, 0 if not -- no risk of insert
|
||||
|
||||
for (auto person : people) { // sorted by key: Adele, Bo, Jenny, John
|
||||
cout << person.first << " is: " << person.second << "\n";
|
||||
}
|
||||
```
|
||||
|
||||
## ✅ 검증 상태 및 신뢰도
|
||||
- **상태:** draft
|
||||
- **검증 단계:** conceptual
|
||||
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
||||
- **신뢰 점수:** 0.86
|
||||
- **중복 검사 결과:** 신규 생성 (New discovery)
|
||||
|
||||
## 🔗 지식 그래프 (Knowledge Graph)
|
||||
- **상위/루트:** [[C++ Tutorial]]
|
||||
- **관련 개념:** [[CPP Sets]], [[CPP Iterators]], [[CPP Data Structures]]
|
||||
- **참조 맥락:** 데이터 구조(STL) 섹션 — Iterators 챕터로 이어짐.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — C++ Maps — https://www.w3schools.com/cpp/cpp_maps.asp
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-07-04: Initial draft synthesized from the W3Schools "C++ Maps" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user