Files
2nd/10_Wiki/Topics/Domain_Programming/Topic_CPP/CPP_Sets.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

4.7 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
cpp-sets C++ Sets Programming_Language draft conceptual
std::set
unique sorted elements C++
C++ 셋
B 0.86 2026-07-04 2026-07-04
cpp
programming-language
w3schools
stl
set
https://www.w3schools.com/cpp/cpp_sets.asp

CPP Sets

🎯 한 줄 통찰 (One-line insight)

set is the first STL container in this series where insertion ORDER is thrown away entirely — every container so far (vector/list/stack/queue/deque) preserved the order elements were added in, but a set auto-sorts on every insert AND silently drops duplicates, meaning cars.insert("BMW") twice is not an error, not a no-op that keeps the old value, but simply invisible — the second insert vanishes with no feedback, which is the opposite of the C mentality where writing the same array slot twice always visibly overwrites it. [S1]

🧠 핵심 개념 (Core concepts)

  • Automatic ascending sort — elements are always kept in sorted order (alphabetical for strings, numeric for ints), regardless of insertion order. [S1]
  • Uniqueness enforced silently — inserting a duplicate value is simply ignored; no error, no exception, no indication. [S1]
  • No index access, no in-place value change — since order is determined by sorting rather than position, elements cannot be retrieved by [i], and an existing element's VALUE cannot be modified (only added via .insert() or removed via .erase()). [S1]
  • greater<type> functor — passed as a second template parameter (set<int, greater<int>> numbers) to reverse the default ascending sort to descending. [S1]
  • .insert() / .erase() / .clear() — add one element / remove one specific element / remove everything. [S1]
  • .size() / .empty() — same semantics as other containers. [S1]
  • Looping — for-each only (like list); no indexed loop since there's no index. [S1]

📖 세부 내용 (Details)

  • Declaration + auto-sort: set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"}; prints in alphabetical order (BMW, Ford, Mazda, Volvo), NOT insertion order. [S1]
  • Numeric sets sort numerically: set<int> numbers = {1, 7, 3, 2, 5, 9}; prints 1,2,3,5,7,9. [S1]
  • Descending order: set<int, greater<int>> numbers = {1, 7, 3, 2, 5, 9}; prints 9,7,5,3,2,1. [S1]
  • Duplicate handling demonstrated directly: set<string> cars = {"Volvo", "BMW", "Ford", "BMW", "Mazda"}; still prints only 4 unique elements. [S1]
  • Add/remove: cars.insert("Tesla"); / cars.erase("Volvo"); / cars.clear();. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • 삽입 순서가 완전히 무시됨: 지금까지의 모든 컨테이너(vector/list/stack/queue/deque)는 삽입 순서를 유지했지만, set은 매번 자동으로 정렬 순서를 재적용하여 삽입 순서 자체가 의미를 잃는다는 점이 이번 챕터에서 확인됨. [S1]
  • 중복 삽입이 조용히 무시됨: C 배열에서 같은 인덱스에 값을 두 번 쓰면 항상 눈에 띄게 덮어써지지만, set에 같은 값을 두 번 insert()하면 아무 에러도 피드백도 없이 두 번째 삽입이 그냥 사라진다는 점이 확인됨. [S1]

🛠️ 적용 사례 (Applied in summary)

현재 발견된 실제 적용 사례가 없습니다 — 자동차 이름 set에 중복값을 넣어 자동으로 걸러지는 것을 보여주는 예제가 원문에서 제시됨. [S1]

💻 코드 패턴 (Code patterns)

A set auto-sorts and silently drops duplicates on insert (C++):

#include <set>
set<string> cars = {"Volvo", "BMW", "Ford", "BMW", "Mazda"};
// Output (sorted, deduplicated): BMW, Ford, Mazda, Volvo

set<int, greater<int>> numbers = {1, 7, 3, 2, 5, 9};
// Descending via greater<type>: 9, 7, 5, 3, 2, 1

cars.insert("Tesla");
cars.erase("Volvo");

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.86
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C++ Sets" page (Astra wiki-curation, P-Reinforce v3.1 format).